def user_forgot(token=None): if not config.CONFIG_DB.has_email_authentication: flask.abort(418) form = auth.form_with_recaptcha(UserForgotForm(obj=auth.current_user_db())) if form.validate_on_submit(): cache.bump_auth_attempt() email = form.email.data user_dbs, cursors = util.get_dbs( model.User.query(), email=email, active=True, limit=2, ) count = len(user_dbs) if count == 1: task.reset_password_notification(user_dbs[0]) return flask.redirect(flask.url_for('welcome')) elif count == 0: form.email.errors.append('This email was not found') elif count == 2: task.email_conflict_notification(email) form.email.errors.append( '''We are sorry but it looks like there is a conflict with your account. Our support team is already informed and we will get back to you as soon as possible.''' ) if form.errors: cache.bump_auth_attempt() return flask.render_template( 'user/user_forgot.html', title=_('Forgot Password?'), html_class='user-forgot', form=form, )
def post(self): """Sends email with token for resetting password to an user""" parser = reqparse.RequestParser() parser.add_argument('email', type=UserValidator.create('existing_email')) args = parser.parse_args() user_db = User.get_by('email', args.email) task.reset_password_notification(user_db) return make_empty_ok_response()
def user_forgot(token=None): if not config.CONFIG_DB.has_email_authentication: flask.abort(418) form = auth.form_with_recaptcha(UserForgotForm(obj=auth.current_user_db())) if form.validate_on_submit(): cache.bump_auth_attempt() email = form.email.data user_dbs, _ = util.get_dbs( model.User.query(), email=email, active=True, limit=2, ) count = len(user_dbs) if count == 1: task.reset_password_notification(user_dbs[0]) return flask.redirect(flask.url_for('welcome')) elif count == 0: form.email.errors.append(u'Имэйл хаяг олдсонгүй') elif count == 2: task.email_conflict_notification(email) form.email.errors.append( u'''Уучлаарай таны дансанд давхардал үүссэн байна. Бид нэн даруй хариуцсан ажилтанд мэдэгдсэн болно. Тусламжийн ажилтан тантай аль болох хурдан холбогдох болно.''') if form.errors: cache.bump_auth_attempt() return flask.render_template( 'user/user_forgot.html', title=u'Нууц үгээ мартсан уу?', html_class='user-forgot', form=form, )