@@ -202,12 +202,15 @@ class KeycloakMixin(OAuth2Mixin):
202
202
"first one:\n %s" ) % '\n ' .join (
203
203
['%s=%s' % (var , os .environ [var ]) for var in vars_proxy ])
204
204
LogEntry .create ('Runtime' , msg )
205
- try :
206
- config ['proxy_host' ] = ':' .join (proxies [0 ].split (':' )[:- 1 ])
207
- config ['proxy_port' ] = int (proxies [0 ].split (':' )[- 1 ])
208
- except IndexError :
209
- LogEntry .create ('Runtime' , ("Your proxy configuration doesn't seem to "
210
- "follow the host:port pattern." ))
205
+ elif len (proxies ) == 1 :
206
+ try :
207
+ config ['proxy_host' ] = ':' .join (proxies [0 ].split (':' )[:- 1 ])
208
+ config ['proxy_port' ] = int (proxies [0 ].split (':' )[- 1 ])
209
+ except IndexError :
210
+ LogEntry .create (
211
+ 'Runtime' ,
212
+ ("Your proxy configuration doesn't seem to "
213
+ "follow the host:port pattern." ))
211
214
212
215
def get_auth_http_client (self ):
213
216
return CurlAsyncHTTPClient ()
@@ -309,8 +312,8 @@ async def post(self, login):
309
312
if not User .exists (username ):
310
313
self .create_new_user (username , user_info , self .idp )
311
314
else :
312
- self .check_verified ( username )
313
- # self.set_secure_cookie("token", access_token )
315
+ self .set_secure_cookie ( "user" , username )
316
+ self .redirect ( "%s/" % qiita_config . portal_dir )
314
317
315
318
except HTTPClientError as e :
316
319
msg = (
@@ -336,123 +339,34 @@ async def post(self, login):
336
339
337
340
@execute_as_transaction
338
341
def create_new_user (self , username , user_info , idp ):
342
+ msg , msg_level = None , None # 'danger', 'success', 'info', 'warning'
339
343
try :
344
+ # create user stub
340
345
created = User .create_oidc (username , user_info , idp )
341
- except QiitaDBDuplicateError :
342
- msg = "Email already registered as a user"
343
- if created :
344
- try :
345
- # qiita_config.base_url doesn't have a / at the end, but the
346
- # qiita_config.portal_dir has it at the beginning but not at
347
- # the end. This constructs the correct URL
348
- msg = (("<h3>User Successfully Registered!</h3><p>Your Qiita "
349
- "account has been successfully registered using '%s', "
350
- "which was provided by the identity provider '%s'. "
351
- "Your account is now awaiting authorization by a Qiita"
352
- " admin.</p><p>If you have any questions regarding "
353
- "the authorization process, please email us at <a "
354
- "href=\" mailto:%s\" >%s</a>.</p>" ) % (
355
- username ,
356
- qiita_config .oidc [self .idp ]['label' ],
357
- qiita_config .help_email ,
358
- qiita_config .help_email ))
359
-
360
- self .redirect (u"%s/?level=success&message=%s" % (
361
- qiita_config .portal_dir , url_escape (msg )))
362
- except Exception :
363
- msg = (("Unable to create account. Please contact the qiita "
364
- "developers at <a href='mailto:%s'>%s</a>" ) % (
365
- qiita_config .help_email , qiita_config .help_email ))
366
- self .redirect (u"%s/?level=danger&message=%s" % (
367
- qiita_config .portal_dir , url_escape (msg )))
368
- return
369
- else :
370
- error_msg = u"?error=" + url_escape (msg )
371
- self .redirect (u"%s/%s" % (qiita_config .portal_dir , error_msg ))
372
-
373
- def check_verified (self , username ):
374
- user = User (username )
375
- if user .level == "unverified" :
376
- msg = (("You are not yet verified by an admin. Please wait or "
377
- "contact the qiita developers at <a href='mailto:%s"
378
- "'>%s</a>" ) % (qiita_config .help_email ,
379
- qiita_config .help_email ))
380
- self .redirect (u"%s/?level=danger&message=%s" % (
381
- qiita_config .portal_dir , url_escape (msg )))
382
- else :
383
- self .set_secure_cookie ("user" , username )
384
- self .redirect ("%s/" % qiita_config .portal_dir )
385
-
386
-
387
- class AdminOIDCUserAuthorization (PortalEditBase ):
388
- """User Verification for Qiita-Account Creation following OIDC Login"""
389
- @authenticated
390
- @execute_as_transaction
391
- def get (self ):
392
- # render page and transfer headers to be included for the table
393
- self .check_admin ()
394
- headers = ["email" , "name" , "affiliation" , "address" , "phone" ]
395
- self .render ('admin_user_authorization.html' , headers = headers ,
396
- submit_url = "/admin/user_authorization/" )
397
-
398
- def post (self ):
399
- # check if logged in user is admin and fetch all checked boxes as well
400
- # as the action
401
- self .check_admin ()
402
- users = map (str , self .get_arguments ('selected' ))
403
- action = self .get_argument ('action' )
404
- # depending on the action either autorize (add) user or delete user
405
- # from db (remove)
406
- for user in users :
407
- try :
408
- with warnings .catch_warnings (record = True ) as warns :
409
- if action == "Authorize_Users" :
410
- self .authorize_user (user )
411
- elif action == "Remove_Users" :
412
- user_to_delete = User (user )
413
- user_to_delete .delete (user )
414
- else :
415
- raise HTTPError (400 ,
416
- reason = "Unknown action: %s" % action )
417
- except QiitaDBError as e :
418
- self .write (action .upper () + " ERROR:<br/>" + str (e ))
419
- return
420
- msg = '; ' .join ([str (w .message ) for w in warns ])
421
- self .write (action + " completed successfully<br/>" + msg )
346
+ if created :
347
+ msg , msg_level = ((
348
+ "<h3>User Successfully Registered!</h3><p>Your user '%s',"
349
+ " provided through '%s', has been successfully registered"
350
+ " and activated. Welcome to Qiita!</p>"
351
+ "<p>Please direct any upcoming questions to "
352
+ "<a href=\" mailto:%s\" >%s</a></p>" ) % (
353
+ username , qiita_config .oidc [idp ]['label' ],
354
+ qiita_config .help_email ,
355
+ qiita_config .help_email )), 'success'
356
+ else :
357
+ msg , msg_level = (
358
+ ("Unable to create account. Please contact the qiita "
359
+ "developers at <a href='mailto:%s'>%s</a>" ) % (
360
+ qiita_config .help_email ,
361
+ qiita_config .help_email )), 'danger'
422
362
423
- @authenticated
424
- @execute_as_transaction
425
- def authorize_user (self , user ):
426
- # authorize user by verifying login manually using tue standard Qiita
427
- # verify function
428
- self .check_admin ()
429
- User .verify_code (user , User (user ).info ['user_verify_code' ], "create" )
430
- return
363
+ # activate user
364
+ User .verify_code (
365
+ username , User (username ).info ['user_verify_code' ], "create" )
431
366
367
+ self .set_secure_cookie ("user" , username )
368
+ except QiitaDBDuplicateError :
369
+ msg , msg_level = "Email already registered as a user" , 'info'
432
370
433
- class AdminOIDCUserAuthorizationAjax (PortalEditBase ):
434
- @authenticated
435
- @execute_as_transaction
436
- def get (self ):
437
- # retrieving users with an unverified level
438
- self .check_admin ()
439
- with qdb .sql_connection .TRN :
440
- sql = """SELECT email,name,affiliation,address,phone
441
- FROM qiita.qiita_user
442
- WHERE user_level_id='5'"""
443
- qdb .sql_connection .TRN .add (sql )
444
- users = qdb .sql_connection .TRN .execute ()[1 :]
445
- result = []
446
- # fetching information for each user
447
- for list in users :
448
- for user in list :
449
- usermail = user [0 ]
450
- user_unit = {}
451
- user_unit ['email' ] = User (usermail ).email
452
- user_unit ['name' ] = User (usermail ).info ['name' ]
453
- user_unit ['affiliation' ] = User (usermail ).info ['affiliation' ]
454
- user_unit ['address' ] = User (usermail ).info ['address' ]
455
- user_unit ['phone' ] = User (usermail ).info ['phone' ]
456
- result .append (user_unit )
457
- # returning information as JSON
458
- self .write (json_encode (result ))
371
+ self .redirect (u"%s/?level=%s&message=%s" % (
372
+ qiita_config .portal_dir , msg_level , url_escape (msg )))
0 commit comments