def change_email(): content = request.get_json() if not content: abort(400) try: new_email = content['new_email'] UserSchema().load({'email': new_email}) except KeyError: abort(400) except ValidationError as validation_error: abort(400, validation_error.messages) if check_user_count_by_email(new_email) > 0: abort(409) if g.user['verified'] != 1: abort(401) token = sha256_crypt.hash(new_email + g.user['password'] + str(time.time())) verification_token = sha256_crypt.hash(str(time.time())) update_email(new_email, token, verification_token) send_email(new_email, email_verification_data(verification_token)) return jsonify(access_token=token)
def register(): content = request.get_json() if not content: abort(400) try: email = content['email'] password = content['password'] UserSchema().load({'email': email, 'password': password}) except KeyError: abort(400) except ValidationError as validation_error: abort(400, validation_error.messages) if (email is not None and password is not None and get_user_by_email(email) is None): token = sha256_crypt.hash(email + password + str(time.time())) verification_token = sha256_crypt.hash(str(time.time())) insert_user(email, generate_password_hash(password), token, verification_token) send_email(email, email_verification_data(verification_token)) return jsonify(access_token=token) else: abort(409)
def resend_confirmation(): token = current_user.generate_confirmation_token() send_email(current_user.email, 'Confirm your email address.', 'users/email/confirm', user=current_user, token=token) flash('New confirmation email has been sent.') return redirect('url_for(staff.search_title)')
def resend_verification(): verification_token = sha256_crypt.hash(str(time.time())) db_result = update_verification_token(verification_token) if db_result.rowcount > 0: send_email(g.user['email'], email_verification_data(verification_token)) else: abort(400) return ('', 204)
def send_password_reset_email(user): token = user.get_reset_password_token() send_email('[Mircoblog] Reset Your Password', sender=current_app.config['ADMINS'][0], recipients=[user.email], text_body=render_template('email/reset_password.txt', user=user, token=token), html_body=render_template('email/reset_password.html', user=user, token=token))
def request_password_reset(): if not current_user.is_anonymous: return redirect(url_for('staff.search_title')) form = RequestPasswordResetForm() if form.validate_on_submit(): user = User.query.filter_by(email=form.email.data.lower()).first() if user: token = user.generate_reset_token() send_email(user.email, 'Reset Your Password', 'users/email/reset_password', user=user, token=token) flash('Please check your email') return redirect(url_for('users.login')) return render_template('users/reset_password.html', form=form)
def register(): form = RegisterForm() if form.validate_on_submit(): user = User(first_name=form.first_name.data, last_name=form.last_name.data, email=form.email.data, password=form.password.data) db.session.add(user) db.session.commit() token = user.generate_confirmation_token() send_email(user.email, 'Confirm your email address.', 'users/email/confirm', user=user, token=token) flash('The email message has been sent on {}'.format(user.email)) return redirect(url_for('staff.search_title')) return render_template('users/register.html', form=form)
def reset_password_request(): content = request.get_json() if not content: abort(400) try: user_email = content['email'] except: abort(400) verification_token = sha256_crypt.hash(str(time.time())) db_result = update_verification_token_by_email(verification_token, user_email) if db_result.rowcount > 0: send_email(user_email, email_reset_password(verification_token)) else: abort(400) return ('', 204)
def reset_password(): content = request.get_json() if not content: abort(400) try: verification_token = content['verification_token'] except: abort(400) user_email = get_email_from_verification(verification_token)['email'] if not user_email: abort(401) new_password = str(randint(10**(6 - 1), (10**6) - 1)) db_result = update_user_pass_by_verify_token( generate_password_hash(new_password), verification_token) if db_result.rowcount > 0: send_email(user_email, email_new_password(new_password)) return ('', 204) else: abort(401)