def request_reset(self): """ Email password reset instructions to user """ context = { 'model': model, 'session': model.Session, 'user': c.user, 'auth_user_obj': c.userobj } try: check_access('request_reset', context) except NotAuthorized: base.abort(403, _('Unauthorized to request reset password.')) if request.method == 'POST': # user_id should be lowercase (for name and email) user_id = request.params.get('user').lower() context = {'model': model, 'user': c.user} user_obj = None try: data_dict = get_action('user_show')(context, {'id': user_id}) user_obj = context['user_obj'] except NotFound: return OnbUserNotFound try: token = tokens.token_show(context, data_dict) except NotFound, e: token = { 'valid': True } # Until we figure out what to do with existing users except Exception, ex: return OnbErr
def test_onboarding(self, mocked_mail_recipient, mocked_send_mail): # step 1 register url = h.url_for(controller='ckanext.hdx_users.controllers.mail_validation_controller:ValidationController', action='register_email') params = {'email': '*****@*****.**', 'nosetest': 'true'} res = self.app.post(url, params) assert_true(json.loads(res.body)['success']) user = model.User.get('*****@*****.**') assert_true(user is not None) assert_true(user.password is None) # step 2 validate token = tkh.token_show({}, {'id': user.id}) url = '/user/validate/' + token.get('token') res = self.app.get(url) assert '<label for="field-email">Your Email Address</label>' in res.body assert 'id="recaptcha"' in res.body assert 'value="*****@*****.**"' in res.body # step 3 details context = {'model': model, 'session': model.Session, 'auth_user_obj': user} url = h.url_for(controller='ckanext.hdx_users.controllers.mail_validation_controller:ValidationController', action='register_details') try: res = self.app.post(url, {}) assert False except KeyError, ex: assert True
def logged_in(self): # redirect if needed came_from = request.params.get('came_from', '') if h.url_is_local(came_from): return h.redirect_to(str(came_from)) if c.user: context = None data_dict = {'id': c.user} user_dict = get_action('user_show')(context, data_dict) # IAuthenticator too buggy, doing this instead try: token = tokens.token_show(context, user_dict) except NotFound, e: token = {'valid': True} # Until we figure out what to do with existing users except:
check_access('user_update', context, data_dict) except NotAuthorized: return OnbNotAuth # except ValidationError, e: # error_summary = e.error_summary # if error_summary == CaptchaNotValid: # return OnbCaptchaErr # return self.error_message(error_summary) except Exception, e: error_summary = e.error_summary return self.error_message(error_summary) # hack to disable check if user is logged in save_user = c.user c.user = None try: token_dict = tokens.token_show(context, data_dict) data_dict['token'] = token_dict['token'] get_action('user_update')(context, data_dict) tokens.token_update(context, data_dict) ue_dict = self._get_ue_dict( data_dict['id'], user_model.HDX_ONBOARDING_USER_VALIDATED) get_action('user_extra_update')(context, ue_dict) ue_dict = self._get_ue_dict(data_dict['id'], user_model.HDX_ONBOARDING_DETAILS) get_action('user_extra_update')(context, ue_dict) if configuration.config.get( 'hdx.onboarding.send_confirmation_email') == 'true': subject = 'Thank you for joining the HDX community'