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