Fixed imports!
parent: tbd commit: ef0e853
1 | use Error; |
2 | use UserAuthenticationToken; |
3 | |
4 | use ; |
5 | |
6 | use ; |
7 | use ; |
8 | use AnyValue; |
9 | use Arc; |
10 | |
11 | use ; |
12 | use ; |
13 | use ; |
14 | |
15 | use |
16 | , |
17 | , | OsRng
18 | RsaPrivateKey, RsaPublicKey, |
19 | ; |
20 | |
21 | use ExposeSecret; |
22 | use Value; |
23 | use PgPool; |
24 | use Mutex; |
25 | |
26 | use crate AuthenticationTokenGranter; |
27 | |
28 | use ; |
29 | |
30 | |
31 | pub pg_pool: PgPool, |
32 | pub this_instance: Instance, |
33 | pub auth_granter: , |
34 | pub settings_provider: , |
35 | |
36 | |
37 | |
38 | |
39 | pool: PgPool, |
40 | this_instance: &Instance, |
41 | granter: , |
42 | settings_provider: , |
43 | |
44 | Self |
45 | pg_pool: pool, |
46 | this_instance: this_instance.clone, |
47 | auth_granter: granter, |
48 | settings_provider, |
49 | |
50 | |
51 | |
52 | |
53 | |
54 | |
55 | async |
56 | Ok |
57 | "display_name" => unsafe |
58 | from_raw |
59 | , |
60 | "bio" => unsafe |
61 | from_raw |
62 | , |
63 | _ => |
64 | return Err; |
65 | |
66 | |
67 | |
68 | async |
69 | let mut provider = self.settings_provider.lock .await; |
70 | |
71 | Ok |
72 | |
73 | |
74 | async |
75 | &mut self, |
76 | user: &User, |
77 | name: &str, |
78 | setting: &Value, |
79 | |
80 | let mut provider = self.settings_provider.lock .await; |
81 | |
82 | provider |
83 | .user_write |
84 | .await |
85 | |
86 | |
87 | async |
88 | Ok |
89 | UserRow, |
90 | r#"SELECT * FROM users WHERE username = $1"#, |
91 | user.username |
92 | |
93 | .fetch_one |
94 | .await |
95 | .is_ok |
96 | |
97 | |
98 | |
99 | |
100 | |
101 | async |
102 | &mut self, |
103 | request: RegisterAccountRequest, |
104 | |
105 | const BITS: usize = 2048; |
106 | |
107 | let private_key = new .unwrap; |
108 | let public_key = from; |
109 | |
110 | let key = |
111 | let mut target: = ; |
112 | |
113 | let mut index = 0; |
114 | let mut iterator = request.password.expose_secret .0.as_bytes .iter; |
115 | while index < 32 |
116 | if let Some = iterator.next |
117 | target= *next; |
118 | index += 1; |
119 | else |
120 | iterator = request.password.expose_secret .0.as_bytes .iter; |
121 | |
122 | |
123 | |
124 | target |
125 | ; |
126 | |
127 | let key: & = &key.into; |
128 | let cipher = new; |
129 | let nonce = generate_nonce; |
130 | let ciphertext = cipher |
131 | .encrypt |
132 | .unwrap; |
133 | |
134 | let private_key_enc = format!; |
135 | |
136 | let salt = generate; |
137 | |
138 | let argon2 = default; |
139 | |
140 | let password_hash = argon2 |
141 | .hash_password |
142 | .unwrap |
143 | .to_string; |
144 | |
145 | let user = match query_as! |
146 | UserRow, |
147 | r#"INSERT INTO users VALUES ($1, $2, $3, $4, $5) returning *"#, |
148 | request.username, |
149 | "example.com", |
150 | password_hash, |
151 | public_key |
152 | .to_public_key_pem |
153 | .unwrap, |
154 | private_key_enc |
155 | |
156 | .fetch_one |
157 | .await |
158 | |
159 | Ok => user, |
160 | Err => |
161 | error!; |
162 | |
163 | return Err; |
164 | |
165 | ; |
166 | |
167 | let mut granter = self.auth_granter.lock .await; |
168 | let token = granter |
169 | .create_token_for |
170 | &User |
171 | username: user.username, |
172 | instance: self.this_instance.clone, |
173 | , |
174 | &self.this_instance, |
175 | |
176 | .await; |
177 | |
178 | Ok |
179 | |
180 | |
181 | async |
182 | &mut self, |
183 | source: &Instance, |
184 | request: AuthenticationTokenRequest, |
185 | |
186 | info!; |
187 | let user = query_as! |
188 | UserRow, |
189 | r#"SELECT * FROM users WHERE username = $1"#, |
190 | request.username |
191 | |
192 | .fetch_one |
193 | .await?; |
194 | |
195 | let hash = new .unwrap; |
196 | |
197 | if default |
198 | .verify_password |
199 | .is_err |
200 | |
201 | info!; |
202 | return Err; |
203 | |
204 | |
205 | let mut granter = self.auth_granter.lock .await; |
206 | let token = granter |
207 | .create_token_for |
208 | &User |
209 | username: user.username, |
210 | instance: self.this_instance.clone, |
211 | , |
212 | &source, |
213 | |
214 | .await; |
215 | |
216 | Ok |
217 | |
218 | |
219 | |
220 | |
221 | |
222 | |
223 | pub username: String, |
224 | pub email: , |
225 | pub password: String, |
226 | pub public_key: String, |
227 | pub enc_private_key: , |
228 | |
229 | |
230 | |
231 | |
232 | pub username: String, |
233 | pub name: String, |
234 | pub value: String, |
235 | |
236 | |
237 | |
238 | |
239 | |
240 | InvalidPassword, |
241 | |
242 |