vapor

Random Alphanumeric String Linux Swift 3

不想你离开。 提交于 2019-12-12 07:27:55
问题 Im having 2 problems when trying to generate a random string in Linux with Swift 3. arc4random_uniform is not available in Linux only on BSD. SO i was able to get away with using random() function. And this worked when i was generating random numbers of a variable size (See code below) func generateRandomNumber() -> Int { var place = 1 var finalNumber = 0; #if os(Linux) for _ in 0..<5 { place *= 10 let randomNumber = Int(random() % 10) + 1 finalNumber += randomNumber * place } #else for _ in

How to create a model in vapor using Mongokitten

有些话、适合烂在心里 提交于 2019-12-12 01:48:31
问题 This is the model and I have to change it to mongo model using mongokitten. This is my friend Model and I have implemented. This but not able to make a nested json like structure for this mode. import Foundation import Vapor import Fluent struct Friend: Model { var exists: Bool = false var id: Node? var name: String var age: Int var email: String var residence: FriendAddress init(name: String, age: Int, email: String ,residence: FriendAddress) { self.name = name self.age = age self.email =

How to upload images from the browser to Amazon S3 using Vapor and Leaf?

久未见 提交于 2019-12-11 12:40:00
问题 I have set up AWS S3 bucket and I'm able to upload files there using Vapor 3 and Postman (PUT -request and with headers: ["x-amz-acl" : "public-read"]) but I would like to do that from the browser (I'm using leaf). So how can I upload image files from the browser? I'm new with HTML, AWS S3 and Vapor. I'm using: Vapor 3 AWS S3 Leaf package S3 package VaporExt package I followed this tutorial to set up everything (except the get request and the bucket policies): https://fivedottwelve.com/blog

Connecting to Oracle Database Using Server Side Swift

99封情书 提交于 2019-12-11 07:28:12
问题 Is it possible yet to connect to an Oracle Database using Swift (raw or a Swift framework) on Linux? What I have done is tried to build a Docker VM, install the Oracle binaries, add the OCILIB package and then connect [tried] using a package called SwiftOracle, which seems unsupported (lots of build issues) and just exposes the OCILIB C code to Swift using a module map and wrapper. I tried this using the Kitura framework and none of this seemed to work - Xcode can't compile because it isn't

Access Session in Leaf template

不羁的心 提交于 2019-12-11 06:18:50
问题 I have a question regarding the Leaf template engine. How can I access the Session values in the Leaf Template? For instance to loop through Flash messages like in Laravel: https://laravel.com/docs/5.3/redirects#redirecting-with-flashed-session-data I can't find a solution to accomplish this. Thanks in advance 回答1: The latest version of Vapor includes the request by default when rendering views. Therefore you'll be able to access the session using #(request.session) // in the latest version

How to pass data from using POST/form leaf template?

帅比萌擦擦* 提交于 2019-12-11 06:04:59
问题 I have a couple of major gaps in my understanding of vapor/leaf/html. I am working from the "todo" example that is created using the beta branch of vapor. First, I made my own fluent model (no problems that I know of): import FluentSQLite import Vapor final class affordatmodel: SQLiteModel { var id: Int? var propertyCost: String var targetEquity: String var interestRate: String var amortization: String var sponsor1: String var sponsor2: String var rent: String var rentInflation: String var

Swift Vapor unsupported_grant_type invalid signature / OAuth access token

感情迁移 提交于 2019-12-11 05:43:08
问题 I am running Xcode 8.1 with Vapor and SWIFT 3. I am posting a request to to google server to get an auth token, so I can call FireBaseDB API, but I get error: unsupported_grant_type/Invalid grant_type. On developers.google.com it says that I have to encode in a URL the following: https://www.googleapis.com/oauth2/v4/token + grant_type + assertion, and pass the encoded URL in the body of the POST request. I pass it as a string. I have noticed that the private key from the JSON file downloaded

Vapor 2 Validation Valid-Type throws “Use of undeclared type Valid”

断了今生、忘了曾经 提交于 2019-12-10 16:58:12
问题 I try to use the Vapor 2 Valid Type, but the compiler only say: "Use of undeclared type Valid". I had read: https://docs.vapor.codes/2.0/validation/package/ + https://docs.vapor.codes/2.0/validation/overview/ In my my Package.swift I have defined /vapor/vapor.git /vapor/validation-provider.git /fluent-provider.git as dependencies. If I try to use Valid<SomeValidator> the compiler says: "Use of undeclared type Valid". The use of import Validation vs import VaporValidation makes no difference.

如何在Android应用程序的“活动”之间传递数据?

吃可爱长大的小学妹 提交于 2019-12-09 17:56:46
我有一种情况,在通过登录页面登录后,每个 activity 上都会有一个退出 button 。 点击 sign-out ,我将传递已登录用户的 session id 以便退出。 谁能指导我如何使 session id 可供所有 activities ? 这种情况的任何替代方法 #1楼 在活动之间传递数据的最方便方法是传递意图。 在您要发送数据的第一个活动中,应添加代码, String str = "My Data"; //Data you want to send Intent intent = new Intent(FirstActivity.this, SecondActivity.class); intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK); intent.putExtra("name",str); //Here you will add the data into intent to pass bw activites v.getContext().startActivity(intent); 您还应该导入 import android.content.Intent; 然后,在下一个Acitvity(SecondActivity)中,应该使用以下代码从意图中检索数据。 String name = this.getIntent(

How do I generate an auth token using JWT for Google firebase?

此生再无相见时 提交于 2019-12-09 17:17:55
问题 So I'm trying to authenticate the Firebase REST API. I'm using the Vapor framework for server side swift and I installed the JWT package. I'm trying to use the data in the serviceAccountKey.json file and JWT to generate an auth token. Here is the code I've tried: let payload = try JSON(node: [ "iat": Date().timeIntervalSince1970, "exp": Date().timeIntervalSince1970 + 3600, "iss": "client_email from serviceAccountKey.json", "aud": "https://accounts.google.com/o/oauth2/token", "scope": [ "https