Old fashioned mustache. mustache - Server Side Swift with Perfect authentication and routes - Stack Overflow

I have server side swift project that is setup to upload files. And I am attempting to authentication to the project so that the files can only be accessed with a valid login. Perfect mustache.

If I change the context: to context I get the stuck in a loop like I am not logged in even after successful login. If I change context: to resp I get stuck in a always logged in state and I can't see the files.

var resp = [String: String]() resp["authenticated"] = "AUTHED: \(request.user.authenticated)" // Render the Mustache template, with context. response.render(template: "index", context: resp) response.completed()

I am close to having the site working the way I want it. The code blow shows the changes I have made and my new hurdle that I need to over come. Which is how to use two different context in the same

How to grow long moustache

routes.add(method:.get, uri: "/", handler: { request, response in if request.user.authenticated == true { guard let accountID = request.user.authDetails?.account.uniqueID else { return } do { let newDir = Dir("./webroot/uploads/\(String(describing: accountID))") let _ = try newDir.create() } catch { } // Context variable, which also initializes the "files" array var context = ["files":[[String:String]]()] // Process only if request.postFileUploads is populated if let uploads = request.postFileUploads, uploads.count > 0 { // iterate through the file uploads. for upload in uploads { // move file let thisFile = File(upload.tmpFileName) do { let _ = try thisFile.moveTo(path: "./webroot/uploads/\(String(describing: accountID))/\(upload.fileName)", overWrite: true) } catch { print(error) } } } // Inspect the uploads directory contents let d = Dir("./webroot/uploads/\(String(describing: accountID))") do{ try d.forEachEntry(closure: {f in context["files"]?.append(["name":f]) }) } catch { print(error) } let setID = [["accountID": accountID]] var dic = [String: String]() for item in setID { for (kind, value) in item { dic.updateValue(value, forKey: kind) } } var context1 = ["files":String()] context1.updateValue(accountID, forKey: "accountID") // Render the Mustache template, with context. response.render(template: "loggedin", context: context) // I only get this context info. response.render(template: "loggedin", context: context1) // This is ignored unless I comment out the line above. response.completed() } else { response.render(template: "index") response.completed() } })

Also changed this section of code.

var authenticationConfig = AuthenticationConfig() authenticationConfig.include("/api/v1/check") authenticationConfig.include("/loggedin") // Added this line authenticationConfig.exclude("/api/v1/login") authenticationConfig.exclude("/api/v1/register")

What mustache fits my face

This is based off the Perfect-Turnstile-SQLite-Demo and parts of this project File-Uploads. The objective was to create a Swift Server Side application that based on the users login it would create a private directory for the user to upload files.

<html> <head> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <link href="/styles/jumbotron-narrow.css" rel="stylesheet"> <title>{{title}}</title> </head> <body> <div class="container"> <div class="header clearfix"> <nav> <ul class="nav nav-pills pull-right"> {{^authenticated}} <li role="presentation"><a href="/login">Log In</a></li> {{/authenticated}} {{#authenticated}} <li role="presentation"><a href="javascript:;" >Logout</a></li> {{/authenticated}} </ul> </nav> <img id="logo" src="/images/perfect-logo-2-0.png" width="176" height="58" alt="Perfect Logo"> <h3 class="text-muted"><a href="/">Perfect Swift Secure File Upload</a></h3> </div> {{#flash}} <div class="alert alert-danger" role="alert"> <span class="glyphicon glyphicon-exclamation-sign" aria-hidden="true"></span> <span class="sr-only">Error:</span> {{flash}} </div> {{/flash}}

Not the answer you're looking for? Browse other questions tagged swift mustache perfect server-side-swift or ask your own question.

How to grow a cool mustache

mustache-styles.com
Overall rating page: 3 / 5 left 112 people.

Posted by at 12:36AM

Tags: old fashioned mustache, the horseshoe mustache, pencil line mustache, best indian beard styles, moustache model, sideburn styles, mustache growth, how to grow long moustache, how to grow a cool mustache, what mustache fits my face

Comments

There are no comments for this post "mustache - Server Side Swift with Perfect authentication and routes - Stack Overflow". Be the first to comment...

Add Comment