Ejemplo n.º 1
0
def password(request, msg=None):
    user = request.user
    if request.method == 'POST':
        form = ChangePasswordForm(request.POST)
        if form.is_valid():
            new_password = form.cleaned_data.get('new_password')
            user.set_password(new_password)
            if user.username == 'admin':
                User.change_build_password(new_password)
            user.is_modified_password = True
            user.save()
            update_session_auth_hash(request, user)
            messages.add_message(request, messages.SUCCESS,
                                 'Your password was successfully changed.')
            return redirect('password')

    else:
        u = STIPUser.objects.get(username=user)
        flg_enable_2fa = False
        if u.totp_secret:
            flg_enable_2fa = True
        form = ChangePasswordForm(instance=user,
                                  initial={'enable_2fa': flg_enable_2fa})
    return render(request, 'core/password.html', {
        'form': form,
        'password_msg': msg
    })
Ejemplo n.º 2
0
def reset_password(request, uidb64, token):
    user_id = urlsafe_base64_decode(uidb64)
    user = User.objects.get(pk=user_id)
    password_change_form = ChangePasswordForm()
    msg = ''
    if not user:
        return render(request, 'frontend/reset_password_invalid.html', {})

    math = default_token_generator.check_token(user, token)
    if not math:
        return render(request, 'frontend/reset_password_invalid.html', {})
    if request.method == 'POST':
        password_change_form = ChangePasswordForm(request.POST)
        if password_change_form.is_valid():
            password = request.POST.get('password', '').strip()
            if user:
                math = default_token_generator.check_token(user, token)
                if math:
                    user.set_password(password)
                    user.save()
                    return render(request,
                                  'frontend/reset_password_successfully.html',
                                  {})

    return render(
        request, 'frontend/reset_password.html', {
            'uidb64': uidb64,
            'token': token,
            'msg': msg,
            'password_change_form': password_change_form
        })
Ejemplo n.º 3
0
def change_password():
    if request.method == "GET":
        token = request.args.get("token")

        if not current_user and not token:
            return redirect("..")

        if not token:
            current_user.password_reset = binascii.b2a_hex(
                os.urandom(20)).decode("utf-8")
            current_user.password_reset_expires = datetime.now() + timedelta(
                days=1)
            db.commit()
            token = current_user.password_reset

        changePwdForm = ChangePasswordForm(token=token)
        return render_template("change.html", changePwdForm=changePwdForm)

    elif request.method == "POST":
        form = ChangePasswordForm(request.form)
        if form.validate():
            token = request.form.get("token")
            password = request.form.get("password")
            user = User.query.filter(User.password_reset == token).first()
            user.set_password(password)
            user.password_reset = None
            user.password_reset_expires = None
            db.commit()
            login_user(user)
            return redirect("panel")
Ejemplo n.º 4
0
def change_password():
    form = ChangePasswordForm(request.form)
    if form.validate_on_submit():
        User.update(
            password = generate_password_hash(form.new_password.data),
        ).where(User.id == form.user_id.data).execute()
        flash('Password successfully changed')
        return redirect(url_for('user.index'))
    return render_template('user/change_password.html', form=form)
Ejemplo n.º 5
0
 def post(self, request):
     form = ChangePasswordForm(request.POST)
     if form.is_valid():
         new_password = request.POST['password_1']
         user_logged = User.objects.get(username=request.user.username)
         user_logged.set_password(new_password)
         user_logged.save()
         return redirect('login')
     else:
         return render(request, 'change_password.html', {'form': form})
Ejemplo n.º 6
0
 def post(self, request):
     form = ChangePasswordForm(request.POST)
     if form.is_valid():
         new_password = request.POST['password_1']
         user_logged = User.objects.get(username=request.user.username)
         user_logged.set_password(new_password)
         user_logged.save()
         return redirect('login')
     else:
         return render(request, 'change_password.html', {'form': form})
Ejemplo n.º 7
0
def password(request):
    user = request.user
    if request.method == 'POST':
        form = ChangePasswordForm(request.POST)
        if form.is_valid():
            new_password = form.cleaned_data.get('new_password')
            user.set_password(new_password)
            user.save()
            messages.add_message(request, messages.SUCCESS, 'Your password were successfully changed.')
    else:
        form = ChangePasswordForm(instance=user)
    return render(request, 'core/password.html', {'form':form})
Ejemplo n.º 8
0
def password(request):
    user = request.user
    if request.method == "POST":
        form = ChangePasswordForm(request.POST)
        if form.is_valid():
            new_password = form.cleaned_data.get("new_password")
            user.set_password(new_password)
            user.save()
            messages.add_message(request, messages.SUCCESS, "Your password were successfully changed.")
    else:
        form = ChangePasswordForm(instance=user)
    return render(request, "core/password.html", {"form": form})
Ejemplo n.º 9
0
def password(request):
    user = request.user
    if request.method == 'POST':
        form = ChangePasswordForm(request.POST)
        if form.is_valid():
            new_password = form.cleaned_data.get('new_password')
            user.set_password(new_password)
            user.save()
            messages.add_message(request, messages.SUCCESS,
                                 'Your password were successfully changed.')
    else:
        form = ChangePasswordForm(instance=user)
    return render(request, 'core/password.html', {'form': form})
Ejemplo n.º 10
0
def password(request):
    user = request.user
    if request.method == 'POST':
        form = ChangePasswordForm(request.POST)
        if form.is_valid():
            new_password = form.cleaned_data.get('new_password')
            user.set_password(new_password)
            user.save()
            update_session_auth_hash(request, user)
            messages.add_message(request, messages.SUCCESS,
                                 'Your password was successfully changed.')
            return redirect('password')

    else:
        form = ChangePasswordForm(instance=user)

    return render(request, 'core/password.html', {
        'form': form,
        'page_user': user
    })
Ejemplo n.º 11
0
def password_modified(request, msg=None):
    user = request.user
    u = STIPUser.objects.get(username=user)
    flg_enable_2fa = False
    if u.totp_secret:
        flg_enable_2fa = True
    form = ChangePasswordForm(instance=user,
                              initial={'enable_2fa': flg_enable_2fa})
    return render(request, 'core/password.html', {
        'form': form,
        'password_msg': 'Please Change Your Password!!!'
    })
Ejemplo n.º 12
0
def change_password(request):
    from core.forms import ChangePasswordForm
    if request.method == 'POST':
        change_pass_form = ChangePasswordForm(request.POST)
        if change_pass_form.is_valid():
            password = change_pass_form.cleaned_data.get('password')
            request.user.set_password(password)
            request.user.save()
            return build_response(constants.RESPONSE_STATUS_SUCCESS,
                                  message='Password Changed',
                                  data={})
        else:
            errors = []
            errors.append(change_pass_form.errors.as_ul())
            errors.append(change_pass_form.non_field_errors().as_ul())
            return build_response(constants.RESPONSE_STATUS_FAIL,
                                  data=errors,
                                  message=constants.FORM_ERROR_MESSAGE)

    return render_to_response('ops-panel/index.html',
                              context={},
                              context_instance=RequestContext(request))
Ejemplo n.º 13
0
def reset_password(request):
    u = User.objects.get(username=request.user.username)
    form = ChangePasswordForm()
    if request.method == "POST":
        if authenticate(request,
                        username=u.username,
                        password=request.POST['old_password']):
            if request.POST['password'] == request.POST['repeated_password']:
                u.set_password(request.POST['password'])
                u.save()
                return redirect(reverse("auth.account"))
        return redirect(reverse("auth.reset.password"))
    return render(
        request, 'auth/form.html', {
            'form': form,
            'action_url': request.path,
            'btn_name': "修改",
            'breadcrumb': get_breadcrumb(request)
        })
Ejemplo n.º 14
0
def profile(request, pk):
    context = {}
    context["user"] = User.objects.get(id=pk)
    context["products"] = Product.objects.filter(user=context["user"])
    context["password_change_form"] = ChangePasswordForm()
    return render(request, "core/profile.html", context)
Ejemplo n.º 15
0
 def get(self, request):
     form = ChangePasswordForm()
     return render(request, 'change_password.html', {'form': form})