Major refactor to handler traits
Added `IntoGiteratedHandler`, which is the new trait for handler functions. This allows us to finally get rid of the Object and ObjectOperation bounds that resulted in hacks around the newer features of the unified stack. Squashed commit of the following: commit 62e1ecf76ee31cda0bab4602d9d00fa0dc2f9158 Author: Amber <[email protected]> Date: Wed Oct 11 09:31:11 2023 -0500 Update commit dfd2d1b0b5d81ee3bc48f0321c6aceaa677e3b8b Author: Amber <[email protected]> Date: Wed Oct 11 09:31:07 2023 -0500 Major refactor to handler traits Added `IntoGiteratedHandler`, which is the new trait for handler functions. This allows us to finally get rid of the Object and ObjectOperation bounds that resulted in hacks around the newer features of the unified stack. Removed dead and legacy code. I think... commit 57b4b398eff32e69f2f4b9700e42a1277a4d1055 Author: Amber <[email protected]> Date: Sun Oct 1 23:05:10 2023 -0500 New handler trait for giterated stack Refactor the old handler trait so it is more generic and can be used for specific kinds of handlers
parent: tbd commit: 90c4780
1 | use Error; |
2 | use StreamExt; |
3 | use UserAuthenticationToken; |
4 | |
5 | use ; |
6 | |
7 | use ; |
8 | use User; |
9 | |
10 | use AuthenticatedUser; |
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 | |
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 | UserRow, |
61 | r#"SELECT * FROM users WHERE username = $1"#, |
62 | user.username |
63 | |
64 | .fetch_one |
65 | .await |
66 | .is_ok |
67 | |
68 | |
69 | async |
70 | &mut self, |
71 | _requester: & , |
72 | user: &User, |
73 | |
74 | let mut repositories = query_as! |
75 | GitRepository, |
76 | r#"SELECT owner_user, name, description, visibility as "visibility: _", default_branch FROM repositories WHERE owner_user = $1"#, |
77 | user.to_string |
78 | |
79 | .fetch_many; |
80 | |
81 | let mut return_repositories = vec!; |
82 | |
83 | while let Some = repositories.next .await |
84 | return_repositories.push |
85 | repository: Repository |
86 | owner: repository_row.owner_user.clone, |
87 | name: repository_row.name, |
88 | instance: self.this_instance.clone, |
89 | , |
90 | owner: repository_row.owner_user, |
91 | visibility: repository_row.visibility, |
92 | description: repository_row.description, |
93 | last_commit: None, |
94 | |
95 | |
96 | |
97 | Ok |
98 | |
99 | |
100 | |
101 | |
102 | |
103 | async |
104 | &mut self, |
105 | request: RegisterAccountRequest, |
106 | |
107 | const BITS: usize = 2048; |
108 | |
109 | let private_key = new .unwrap; |
110 | let public_key = from; |
111 | |
112 | let key = |
113 | let mut target: = ; |
114 | |
115 | let mut index = 0; |
116 | let mut iterator = request.password.expose_secret .0.as_bytes .iter; |
117 | while index < 32 |
118 | if let Some = iterator.next |
119 | target= *next; |
120 | index += 1; |
121 | else |
122 | iterator = request.password.expose_secret .0.as_bytes .iter; |
123 | |
124 | |
125 | |
126 | target |
127 | ; |
128 | |
129 | let key: & = &key.into; |
130 | let cipher = new; |
131 | let nonce = generate_nonce; |
132 | let ciphertext = cipher |
133 | .encrypt |
134 | .unwrap; |
135 | |
136 | let private_key_enc = format!; |
137 | |
138 | let salt = generate; |
139 | |
140 | let argon2 = default; |
141 | |
142 | let password_hash = argon2 |
143 | .hash_password |
144 | .unwrap |
145 | .to_string; |
146 | |
147 | let user = match query_as! |
148 | UserRow, |
149 | r#"INSERT INTO users VALUES ($1, $2, $3, $4, $5) returning *"#, |
150 | request.username, |
151 | "example.com", |
152 | password_hash, |
153 | public_key |
154 | .to_public_key_pem |
155 | .unwrap, |
156 | private_key_enc |
157 | |
158 | .fetch_one |
159 | .await |
160 | |
161 | Ok => user, |
162 | Err => |
163 | error!; |
164 | |
165 | return Err; |
166 | |
167 | ; |
168 | |
169 | let mut granter = self.auth_granter.lock .await; |
170 | let token = granter |
171 | .create_token_for |
172 | &User |
173 | username: user.username, |
174 | instance: self.this_instance.clone, |
175 | , |
176 | &self.this_instance, |
177 | |
178 | .await; |
179 | |
180 | Ok |
181 | |
182 | |
183 | async |
184 | &mut self, |
185 | source: &Instance, |
186 | request: AuthenticationTokenRequest, |
187 | |
188 | let user = query_as! |
189 | UserRow, |
190 | r#"SELECT * FROM users WHERE username = $1"#, |
191 | request.username |
192 | |
193 | .fetch_one |
194 | .await?; |
195 | |
196 | let hash = new .unwrap; |
197 | |
198 | if default |
199 | .verify_password |
200 | .is_err |
201 | |
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 | |
233 | pub username: String, |
234 | pub name: String, |
235 | pub value: String, |
236 | |
237 | |
238 | |
239 | |
240 | |
241 | InvalidPassword, |
242 | |
243 |