def form(request): message = None if request.method == 'POST': form = UserResetPasswordForm(request.POST, request=request) if form.is_valid(): user = form.found_user user_ban = Ban.objects.check_ban(username=user.username, email=user.email) if user_ban: return error_banned(request, user, user_ban) elif user.activation != User.ACTIVATION_NONE: return redirect_message(request, messages.INFO, _("%(username)s, your account has to be activated in order for you to be able to request new password.") % {'username': user.username}) user.token = random_string(12) user.save(force_update=True) user.email_user( request, 'users/password/confirm', _("Confirm New Password Request") ) return redirect_message(request, messages.INFO, _("%(username)s, new password request confirmation has been sent to %(email)s.") % {'username': user.username, 'email': user.email}) else: message = Message(form.non_field_errors()[0], messages.ERROR) else: form = UserResetPasswordForm(request=request) return render_to_response('reset_password.html', { 'message': message, 'form': form, }, context_instance=RequestContext(request));
def reset(request, username="", user="******", token=""): user = int(user) try: user = User.objects.get(pk=user) user_ban = Ban.objects.check_ban(username=user.username, email=user.email) if user_ban: return error_banned(request, user, user_ban) if user.activation != User.ACTIVATION_NONE: return redirect_message(request, messages.INFO, _("%(username)s, your account has to be activated in order for you to be able to request new password.") % {'username': user.username}) if not token or not user.token or user.token != token: return redirect_message(request, messages.ERROR, _("%(username)s, request confirmation link is invalid. Please request new confirmation link.") % {'username': user.username}) new_password = random_string(6) user.token = None user.set_password(new_password) user.save(force_update=True) # Logout signed in and kill remember me tokens Session.objects.filter(user=user).update(user=None) Token.objects.filter(user=user).delete() # Set flash and mail new password user.email_user( request, 'users/password/new', _("Your New Password"), {'password': new_password} ) return redirect_message(request, messages.SUCCESS, _("%(username)s, your password has been changed with new one that was sent to %(email)s.") % {'username': user.username, 'email': user.email}) except User.DoesNotExist: return error404(request)
def form(request): message = None if request.method == 'POST': form = UserSendActivationMailForm(request.POST, request=request) if form.is_valid(): user = form.found_user user_ban = Ban.objects.check_ban(username=user.username, email=user.email) if user_ban: return error_banned(request, user, user_ban) if user.activation == User.ACTIVATION_NONE: return redirect_message(request, messages.INFO, _("%(username)s, your account is already active.") % {'username': user.username}) if user.activation == User.ACTIVATION_ADMIN: return redirect_message(request, messages.INFO, _("%(username)s, only board administrator can activate your account.") % {'username': user.username}) user.email_user( request, 'users/activation/resend', _("Account Activation"), ) return redirect_message(request, messages.SUCCESS, _("%(username)s, e-mail containing new activation link has been sent to %(email)s.") % {'username': user.username, 'email': user.email}) else: message = Message(form.non_field_errors()[0], messages.ERROR) else: form = UserSendActivationMailForm(request=request) return render_to_response('resend_activation.html', { 'message': message, 'form': form, }, context_instance=RequestContext(request));
def activate(request, username="", user="******", token=""): user = int(user) try: user = User.objects.get(pk=user) current_activation = user.activation # Run checks user_ban = Ban.objects.check_ban(username=user.username, email=user.email) if user_ban: return error_banned(request, user, user_ban) if user.activation == User.ACTIVATION_NONE: return redirect_message(request, messages.INFO, _("%(username)s, your account is already active.") % {'username': user.username}) if user.activation == User.ACTIVATION_ADMIN: return redirect_message(request, messages.INFO, _("%(username)s, only board administrator can activate your account.") % {'username': user.username}) if not token or not user.token or user.token != token: return redirect_message(request, messages.ERROR, _("%(username)s, your activation link is invalid. Try again or request new activation e-mail.") % {'username': user.username}) # Activate and sign in our member user.activation = User.ACTIVATION_NONE sign_user_in(request, user) # Update monitor User.objects.resync_monitor() if current_activation == User.ACTIVATION_CREDENTIALS: return redirect_message(request, messages.SUCCESS, _("%(username)s, your account has been successfully reactivated after change of sign-in credentials.") % {'username': user.username}) else: return redirect_message(request, messages.SUCCESS, _("%(username)s, your account has been successfully activated. Welcome aboard!") % {'username': user.username}) except User.DoesNotExist: return error404(request)
def activate(request, username="", user="******", token=""): user = int(user) try: user = User.objects.get(pk=user) current_activation = user.activation # Run checks user_ban = Ban.objects.check_ban(username=user.username, email=user.email) if user_ban: return error_banned(request, user, user_ban) if user.activation == User.ACTIVATION_NONE: return redirect_message(request, Message(_("%(username)s, your account is already active.") % {'username': user.username}), 'info') if user.activation == User.ACTIVATION_ADMIN: return redirect_message(request, Message(_("%(username)s, only board administrator can activate your account.") % {'username': user.username}), 'info') if not token or not user.token or user.token != token: return redirect_message(request, Message(_("%(username)s, your activation link is invalid. Try again or request new activation e-mail.") % {'username': user.username}), 'error') # Activate and sign in our member user.activation = User.ACTIVATION_NONE sign_user_in(request, user) # Update monitor User.objects.resync_monitor(request.monitor) if current_activation == User.ACTIVATION_CREDENTIALS: return redirect_message(request, Message(_("%(username)s, your account has been successfully reactivated after change of sign-in credentials.") % {'username': user.username}), 'success') else: return redirect_message(request, Message(_("%(username)s, your account has been successfully activated. Welcome aboard!") % {'username': user.username}), 'success') except User.DoesNotExist: return error404(request)
def form(request): message = None if request.method == 'POST': form = UserSendActivationMailForm(request.POST, request=request) if form.is_valid(): user = form.found_user user_ban = Ban.objects.check_ban(username=user.username, email=user.email) if user_ban: return error_banned(request, user, user_ban) if user.activation == User.ACTIVATION_NONE: return redirect_message(request, Message(_("%(username)s, your account is already active.") % {'username': user.username}), 'info') if user.activation == User.ACTIVATION_ADMIN: return redirect_message(request, Message(_("%(username)s, only board administrator can activate your account.") % {'username': user.username}), 'info') user.email_user( request, 'users/activation/resend', _("Account Activation"), ) return redirect_message(request, Message(_("%(username)s, e-mail containing new activation link has been sent to %(email)s.") % {'username': user.username, 'email': user.email}), 'success') else: message = Message(form.non_field_errors()[0], 'error') else: form = UserSendActivationMailForm(request=request) return request.theme.render_to_response('resend_activation.html', { 'message': message, 'form': FormLayout(form), }, context_instance=RequestContext(request));
def decorator(*args, **kwargs): request = args[0] try: if request.ban.is_banned(): return error_banned(request); return f(*args, **kwargs) except AttributeError: pass return f(*args, **kwargs)
def reset(request, username="", user="******", token=""): user = int(user) try: user = User.objects.get(pk=user) user_ban = Ban.objects.check_ban(username=user.username, email=user.email) if user_ban: return error_banned(request, user, user_ban) if user.activation != User.ACTIVATION_NONE: return redirect_message( request, Message( _("%(username)s, your account has to be activated in order for you to be able to request new password." ) % {'username': user.username}), 'info') if not token or not user.token or user.token != token: return redirect_message( request, Message( _("%(username)s, request confirmation link is invalid. Please request new confirmation link." ) % {'username': user.username}), 'error') new_password = random_string(6) user.token = None user.set_password(new_password) user.save(force_update=True) # Logout signed in and kill remember me tokens Session.objects.filter(user=user).update(user=None) Token.objects.filter(user=user).delete() # Set flash and mail new password user.email_user(request, 'users/password/new', _("Your New Password"), {'password': new_password}) return redirect_message( request, Message( _("%(username)s, your password has been changed with new one that was sent to %(email)s." ) % { 'username': user.username, 'email': user.email }), 'success') except User.DoesNotExist: return error404(request)
def form(request): message = None if request.method == 'POST': form = UserResetPasswordForm(request.POST, request=request) if form.is_valid(): user = form.found_user user_ban = Ban.objects.check_ban(username=user.username, email=user.email) if user_ban: return error_banned(request, user, user_ban) elif user.activation != User.ACTIVATION_NONE: return redirect_message( request, Message( _("%(username)s, your account has to be activated in order for you to be able to request new password." ) % {'username': user.username}), 'info') user.token = random_string(12) user.save(force_update=True) user.email_user(request, 'users/password/confirm', _("Confirm New Password Request")) return redirect_message( request, Message( _("%(username)s, new password request confirmation has been sent to %(email)s." ) % { 'username': user.username, 'email': user.email }), 'info') else: message = Message(form.non_field_errors()[0], 'error') else: form = UserResetPasswordForm(request=request) return request.theme.render_to_response( 'reset_password.html', { 'message': message, 'form': FormLayout(form), }, context_instance=RequestContext(request))