Ejemplo n.º 1
0
def reset_password(payload):
    form = ResetPasswordForm()
    pageTitle = "reset password"

    # disallows password reset link to be reused
    unhashed_payload = User.check_password_reset_link(payload)
    user_email = unhashed_payload[0]
    oldhash = unhashed_payload[1]

    if user_email:
        user_oldhash = User.get(email=user_email).pwdhash[:10]
        if oldhash != user_oldhash:
            flash("Token has been used previously.  Please try again.")
            return redirect(url_for('.forgotPassword'))

    if not user_email:
        flash("Token incorrect or has expired.  Please try again.")
        return redirect(url_for('.forgotPassword'))

    if request.method == 'POST':
        if not form.validate():
            return render_template('users/resetPassword.html',
                                   form=form,
                                   pageTitle=pageTitle)
        else:
            user = User.get(email=user_email)
            user.set_password(form.password.data)
            user.save()
            #email password reset
            flash("Password has been reset, please login")
            return redirect(url_for('.login'))
    elif request.method == 'GET':
        return render_template('users/resetPassword.html',
                               form=form,
                               pageTitle=pageTitle)
def reset_password(request):
    user = User.objects.get(id = request.user.id)
    if request.method == "POST":
        form = ResetPasswordForm(data=request.POST)
        if form.is_valid():
            new_password = form.cleaned_data.get('password')
            user.set_password(new_password)
            user.save()
            return HttpResponseRedirect(reverse('index'))
    else:
        form = ResetPasswordForm()
    return render(request, 'reset_password.html', {'form':form})
Ejemplo n.º 3
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    user = User.verify_reset_password_token(token)
    if not user:
        return redirect(url_for('index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash(_('Your password has been reset.'))
        return redirect(url_for('login'))
    return render_template('reset_password.html', form=form)
Ejemplo n.º 4
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    user=User.verify_reset_password_token(token)
    if not user:
        return redirect(url_for("index"))
    form=ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash("your password is reset")
        return redirect(url_for("login"))
    return render_template("reset_password.html",form=form)
Ejemplo n.º 5
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    user = User.verify_reset_password_token(token)
    if not user:
        return redirect(url_for('main.index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.password = form.password.data
        db.session.commit()
        flash('密码已经重置')
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password.html', form=form)
Ejemplo n.º 6
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    user = User.verify_reset_password_token(token)
    if not user:
        return redirect(url_for('index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash('Your password has been reset.')
        return redirect(url_for('login'))
    return render_template('reset_password.html', form=form)
Ejemplo n.º 7
0
def changepassword():
    if current_user.is_authenticated:
        user = current_user
    else:
        return redirect(url_for('landing'))

    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash('Your password has been reset.')
        return redirect(url_for('profile'))
    return render_template('reset-password.html', form=form)
Ejemplo n.º 8
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for("index"))
    user = Users.verify_reset_password_token(token)
    if not user:
        return redirect(url_for("index"))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        user.update()
        flash("Your password has been reset.")
        return redirect(url_for("login"))
    return render_template("reset_password.html", form=form)
Ejemplo n.º 9
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    user = User.verify_reset_password_token(token)
    if not user:
        return redirect(url_for('index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        #User is already added, No "db.session.add()
        flash('Password Reset Successfully')
        return redirect(url_for('login'))
    return render_template('reset_password.html', form=form)
Ejemplo n.º 10
0
def reset():
    param_email_address = request.args.get("email")
    param_password_reset_token = request.args.get("token")
    user = User.query.filter_by(email_address=param_email_address).first()
    form = ResetPasswordForm(email_address=param_email_address)
    if user and user.password_reset_token and bcrypt.check_password_hash(user.password_reset_token.token, param_password_reset_token):
        if form.validate_on_submit():
            user.password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
            db.session.delete(user.password_reset_token)
            db.session.commit()
            flash("Password successfully reset.", 'success')
            return redirect(url_for('login', email=param_email_address))
        return render_template('reset.html', form=form)
    return redirect(url_for('login', email=param_email_address))
Ejemplo n.º 11
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    user = User.verify_reset_token(token)
    if not user:
        flash("Invalid or expired token", "warning")
        return redirect(url_for('reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash("Your password has been reset. You are now able to log in.", "success")
        return redirect(url_for('login'))
    return render_template('reset_password.html', form=form)
Ejemplo n.º 12
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('user', first_name=current_user.first_name))
    user = User.verify_reset_token(token)
    if not user:
        flash('لینک منقضی شده است')
        return redirect(url_for('forgot'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash('رمز عبور شما تغییر یافت')
        return redirect(url_for('login'))
    return render_template('reset_password.html', form=form, title='تغییر رمز')
Ejemplo n.º 13
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('密钥过期或失效', 'warning')
        return redirect(url_for('reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash('重置密码成功', 'success')
        return redirect(url_for('login'))
    return render_template('reset_token.html', title='重置密码', form=form)
Ejemplo n.º 14
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    user = User.verify_reset_password_token(token)
    if not user:
        return redirect(url_for('login'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash('Votre mot de passe à été changé.')
        return redirect(url_for('login'))
    return render_template('reset_password.html',
                           title='Changer mot de passe',
                           form=form)
Ejemplo n.º 15
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('That is an invalid or expired token', 'warning')
        return redirect(url_for('reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash('Your password has been updated! You are now able to log in', 'success')
        return redirect(url_for('login'))
    return render_template('reset_token.html', title='Reset Password', form=form)    
Ejemplo n.º 16
0
def reset_password_request():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if not user:
            flash('Invalid username')
            return redirect(url_for('reset_password_request'))
        user.set_password(form.password.data)
        db.session.commit()
        flash('Your password has been reset.')
        return redirect(url_for('login'))
    return render_template('reset_password_request.html',
                           title='Reset Password', form=form)
Ejemplo n.º 17
0
def reset_password(token):
    try:
        email = confirm_token(token)
    except:
        flash('The confirmation link is invalid or has expired.', 'danger')
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    user = User.query.filter_by(email=email).first_or_404()
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        update_by_entity(user)
        flash('Your password has been reset.')
        return redirect(url_for('auth.login'))
    return render_template('reset_password.html', form=form)
Ejemplo n.º 18
0
def reset_token(token):
	if current_user.is_authenticated:
		return redirect(url_for('home'))
	user = User.verify_reset_token(token)	# Metod som verifierar att det är rätt token samt plockar fram rätt objekt
	if user is None:						# Om det inte finns någon user eller om ditt token har "dött" (tar 30min), kör nedan
		flash('Bad or expired token', 'warning')	# Röd banner ('warning') med text om att det inte fungerar
		return redirect(url_for('reset_request'))	# Skickar tillbaks en till sidan för att skapa ett nytt token och få ett nytt mail
	form = ResetPasswordForm()						# Form från forms.py
	if form.validate_on_submit():					# OM SubmitField klickas, kör nedan
		hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8') # Hashar det nya lösenordet som anges i PasswordField
		user.password = hashed_password		# Updaterar det aktuella user-objektet
		db.session.commit()					# commitar till databasen (viola det är nu ändrat)
		flash('Your password has been reset! You can now login', 'success')
		return redirect(url_for('login'))	# Redirectar dig till login så att du kan logga in med det nya lösenordet
	return render_template('reset_token.html', title='Reset Password', form=form)	# Renderar reset_token.html
Ejemplo n.º 19
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    user = User.verify_token('reset_password', token)
    if not user:
        flash('Pedido inválido, gere um novo pedido para alterar sua senha.',
              'danger')
        return redirect(url_for('home'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash('Sua senha foi alterada.', 'success')
        return redirect(url_for('login'))
    return render_template('reset_password.html', form=form)
Ejemplo n.º 20
0
def reset_password(token):
    if current_user.is_authenticated:  #Make sure user isn't logged in
        return redirect(url_for('index'))
    user = User.verify_reset_password_token(
        token)  # verify token returning user
    if not user:
        return redirect(
            url_for('index'))  # if the token was not verified, returned None
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash('Your password has been reset.')
        return redirect(url_for('login'))
    return render_template('reset_password.html', form=form)
Ejemplo n.º 21
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('proute.index'))
    contributor = Contributor.verify_reset_password_token(token)
    if not contributor:
        return redirect(url_for('proute.index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        contributor.set_password(form.password.data)
        db.session.commit()
        flash('Your password has been reset.')
        return redirect(url_for('auths.login'))
    return render_template('reset_password.html',
                           title="New Password?",
                           form=form)
Ejemplo n.º 22
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    user = User.verify_reset_password_token(token)
    if not user:
        return redirect(url_for('index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash('Ditt lösenord har blivit återställt.')
        return redirect(url_for('login'))
    return render_template('reset_password.html',
                           drop_down_cats=drop_down_cats,
                           form=form)
Ejemplo n.º 23
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('invalid_action'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('Invalid or expired token. Please try again.', 'warning')
        return redirect(url_for('reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash('Password has been reset.', 'success')
        return redirect(url_for('login'))
    return render_template('reset_password_token_valid.html', title='Reset Password', form=form)
Ejemplo n.º 24
0
def change_password():
    user = current_user

    form = ResetPasswordForm()
    if form.validate_on_submit():
        if user.check_password(form.current_password.data):
            user.set_password(form.password.data)
            db.session.commit()
            flash('Your password has been reset.')
            logout_user()
            return redirect(url_for('login'))
        else:
            flash('Invalid current password')

    return render_template('change_password.html', form=form)
Ejemplo n.º 25
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user = User.check_reset_password_token(token=token)
        if user:
            user.password = bcrypt.generate_password_hash(form.password.data)
            db.session.commit()
            flash('Your reset is done, you can login now', category='info')
            return redirect(url_for('login'))
        else:
            flash('this user is not exist', category='info')
            return redirect(url_for('login'))
    return render_template('reset_password.html', form=form)
Ejemplo n.º 26
0
def reset_password_step0(request):
    form = ResetPasswordForm()
    if request.method == 'POST':
        form = ResetPasswordForm(request.POST)
        if form.is_valid():
            token = Token()
            token.user = User.objects.get(email=form.cleaned_data.get('email'))
            token.save()
            link = request.build_absolute_uri(reverse('reset-password-step1', args=[token.token]))
            send_mail('Reset password', settings.RESET_PASSWORD_EMAIL % (link,),
              '*****@*****.**', [token.user.email, ])
            messages.add_message(request, messages.SUCCESS,
                                 _('Please click the password reset link which was sent to your email'))
            return redirect('login_view')
    return render(request, 'app/reset-password/reset-password-step0.html', locals())
Ejemplo n.º 27
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    user=User.verify_reset_token(token)
    if user is None:
        flash('That is an invalid or expired token','warning')
        return redirect(url_for(reset_request))
    form=ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash('Your password has been updated')
        return redirect(url_for('login'))
        
    return render_template('reset_token.html',title='RESET PASSWORD',form=form)
Ejemplo n.º 28
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    user = User.verify_reset_password_token(token)
    if not user:
        return redirect(url_for('index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash(_('Ваш пароль будет изменен.'))
        return redirect(url_for('login'))
    return render_template('reset_password.html',
                           form=form,
                           edit_profile_flg=False)
Ejemplo n.º 29
0
def reset_password(token):
    # if already logged in send to home page
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    # if not correct user, send to homepage
    user = User.verify_reset_password_token(token)
    if not user:
        return redirect(url_for('index'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash('Your password has been changed!')
        return redirect(url_for('login'))
    return render_template('reset_password.html', form=form)
Ejemplo n.º 30
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('That is an invalid or expired token', 'warning')
        return redirect(url_for('reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash('Şifrəniz yeniləndi! İndi hesabınıza daxil ola bilərsiniz.', 'success')
        return redirect(url_for('login'))
    return render_template('app/user/reset_token.html', title='Şifrəni Yenilə', form=form)
Ejemplo n.º 31
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    user = User.verify_reset_password_token(token)
    if not user:
        return redirect(url_for('register'))
    reset_password_form = ResetPasswordForm()
    if reset_password_form.validate_on_submit():
        user.set_password(reset_password_form.user_password.data)
        db.session.commit()
        flash('your password has been reset')
        return redirect(url_for('login'))
    return render_template('reset_password.html',
                           title='reset password',
                           reset_password_form=reset_password_form)
Ejemplo n.º 32
0
def reset_password(token):
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    user = User.verify_reset_password_token(token)
    if not user:
        return redirect(url_for('index'))
    form = ResetPasswordForm()

    if request.method == 'POST' and form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash('Your password ahs been changed')
        return redirect(url_for('login'))
    return render_template("reset_password.html",
                           title="Reset Password",
                           form=form)
Ejemplo n.º 33
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect('/')
    user = User.verify_reset_token(token)
    if user is None:
        flash('-That is an invalid or expired token')
        return redirect('/')
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash('|Your password has been updated.')
        return redirect('/')
    return render_template('reset_token.html',
                           title='Reset Password',
                           form=form)
Ejemplo n.º 34
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    user = User.verify_token(token)
    if user is None:
        flash('This is an expired or invalid token.')
        return redirect(url_for('reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        user.set_password(form.password.data)
        db.session.commit()
        flash('Password updated successfully.')
        return redirect(url_for('login'))
    return render_template('reset_token.html',
                           form=form,
                           title='Reset Password ')
Ejemplo n.º 35
0
def reset_password(token):
    '''重设密码'''
    if RT.query.get(token):
        return render_template('feedback.html', status=False, message=_('此密码重置链接已被使用过。'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        RT.add(token)
        try:
            email = ts.loads(token, salt="password-reset-key", max_age=86400)
        except:
            return render_template('feedback.html', status=False, message=_('此密码重置链接无效,请准确复制邮件中的链接。'))
        user = User.query.filter_by(email=email).first_or_404()
        password = form['password'].data
        user.set_password(password)
        logout_user()
        flash('密码已经修改,请使用新密码登录。')
        return redirect(url_for('home.signin'))
    return render_template('reset-password.html',form=form)
Ejemplo n.º 36
0
def resetpass():
    user = current_user
    if 'activation_key' in request.values and request.values['activation_key']:
        user = User.query.filter_by(
            activation_key=request.values['activation_key']).first()
    if user is None:
        abort(403)
    # setup new password
    form = ResetPasswordForm(activation_key=user.activation_key)
    if form.validate_on_submit():
        user.password = form.password.data
        user.activation_key = None
        user.save()
        flash(u"你的密码已成功重设。", "successfully")
        if current_user:
            logout_user()
        return redirect(url_for("account.login"))
    return render_template("account/resetpass.html", form=form)
Ejemplo n.º 37
0
def password_reset(request, user_id,hashed):
    if request.method=="POST":
        form = ResetPasswordForm(request.POST)
        if form.is_valid():
            clean = form.cleaned_data
            if clean['password'] == clean['repeat_password']:
                user = User.objects.get(id = user_id)
                temp_date = user.get_profile().temp_hash
                m = hashlib.sha224(str(temp_date)).hexdigest()
                if m != hashed:
                    return HttpResponseRedirect("/")
                user.set_password(clean['password'])
                user.save()
                return HttpResponseRedirect("/")
            else:
                messages.error(request, "Please make sure the passwords are the same")
    form = ResetPasswordForm()
    return render_to_response("main/reset_password.html", locals(),
            context_instance=RequestContext(request))
Ejemplo n.º 38
0
def reset_password(token):
    """Check for the reset token. If valid, allow the user to set a
    new password.
    """

    serializer = Serializer(current_app.config['SECRET_KEY'])

    try:
        data = serializer.loads(token)
    except:
        flash('Invalid or expired token')
        return redirect(url_for('mod_feed.index'))

    form = ResetPasswordForm()

    if form.validate_on_submit():
        user = User.query.get(data['reset_id'])
        user.password = form.new_password.data
        db.session.add(user)
        db.session.commit()
        flash('Your password has been successfully changed')
        return redirect(url_for('mod_feed.index'))

    return render_template('auth/reset_password.html', form=form)
Ejemplo n.º 39
0
def password(request):

    if request.user.is_authenticated():
        form = ResetPasswordForm()
        if request.method=="POST":
            form = ResetPasswordForm(request.POST)
            if form.is_valid():
                clean = form.cleaned_data
                if clean['password'] == clean['repeat_password']:
                    request.user.set_password(clean['password'])
                    request.user.save()
                    return HttpResponseRedirect("/accounts/profile/")
        return render_to_response("main/reset_password.html", locals(),
                context_instance=RequestContext(request))
    else:
        form = EmailForm()
        if request.method=="POST":
            form = EmailForm(request.POST)
            if form.is_valid():
                clean = form.cleaned_data
                email = clean['email']
                user = User.objects.get(email = email)
                temp_date = datetime.datetime.now()
                user.get_profile().temp_hash = str(temp_date)
                user.get_profile().save()
                m = hashlib.sha224(str(temp_date)).hexdigest()
                rel_url = "/accounts/pw_rst/"+str(user.id)+"/"+m+"/"
                link_url = request.build_absolute_uri(rel_url)
                print link_url
                subject, from_email, to = 'Password Reset' , 'Idea Otter<*****@*****.**>', '*****@*****.**'
                text_content = 'Hey,\n\n You (or someone else) has asked to reset your password. Click on the url to it\n\n ' +link_url +'\n\n'
                html_content = '<h2>Password Reset</h2><p>You requested a password reset</p><p>Click <a href="'+link_url+'">here</a>!</p>'
                print text_content
                print html_content
                msg = EmailMultiAlternatives(subject, text_content, from_email, [email])
                msg.attach_alternative(html_content, "text/html")
                print msg
                msg.send()
        return render_to_response("main/lost_password.html", locals(),
                context_instance=RequestContext(request))