def forgot_pass(): if not g.notebook.conf()['email']: return current_app.message( _('The account recovery system is not active.')) username = request.values.get('username', '').strip() if not username: return render_template( os.path.join('html', 'accounts', 'account_recovery.html')) def error(msg): return current_app.message(msg, url_for('forgot_pass')) try: user = g.notebook.user(username) except KeyError: return error(_('Username is invalid.')) if not user.is_email_confirmed(): return error(_("The e-mail address hasn't been confirmed.")) #XXX: some of this could be factored out into a random passowrd #function. There are a few places in admin.py that also use it. from random import choice import string chara = string.letters + string.digits old_pass = user.password() password = ''.join([choice(chara) for i in range(8)]) from sagenb.notebook.smtpsend import send_mail from sagenb.notebook.register import build_password_msg # TODO: make this come from the server settings listenaddr = g.notebook.interface port = g.notebook.port fromaddr = 'no-reply@%s' % listenaddr body = build_password_msg(password, username, listenaddr, port, g.notebook.secure) destaddr = user.get_email() try: send_mail(fromaddr, destaddr, _("Sage Notebook Account Recovery"), body) except ValueError: # the email address is invalid return error( _("The new password couldn't be sent to %(dest)s.", dest=destaddr)) else: g.notebook.user_manager().set_password(username, password) return current_app.message( _("A new password has been sent to your e-mail address."), url_for('base.index'))
def forgot_pass(): if not g.notebook.conf()["email"]: return current_app.message(_("The account recovery system is not active.")) username = request.values.get("username", "").strip() if not username: return render_template(os.path.join("html", "accounts", "account_recovery.html")) def error(msg): return current_app.message(msg, url_for("forgot_pass")) try: user = g.notebook.user(username) except KeyError: return error(_("Username is invalid.")) if not user.is_email_confirmed(): return error(_("The e-mail address hasn't been confirmed.")) # XXX: some of this could be factored out into a random passowrd # function. There are a few places in admin.py that also use it. from random import choice import string chara = string.letters + string.digits old_pass = user.password() password = "".join([choice(chara) for i in range(8)]) from sagenb.notebook.smtpsend import send_mail from sagenb.notebook.register import build_password_msg # TODO: make this come from the server settings listenaddr = g.notebook.interface port = g.notebook.port fromaddr = "no-reply@%s" % listenaddr body = build_password_msg(password, username, listenaddr, port, g.notebook.secure) destaddr = user.get_email() try: send_mail(fromaddr, destaddr, _("Sage Notebook Account Recovery"), body) except ValueError: # the email address is invalid return error(_("The new password couldn't be sent to %(dest)s.", dest=destaddr)) else: g.notebook.user_manager().set_password(username, password) return current_app.message(_("A new password has been sent to your e-mail address."), url_for("base.index"))
def forgot_pass(): if not g.notebook.conf()['email']: return current_app.message('The account recovery system is not active.') username = request.values.get('username', '').strip() if not username: return render_template(os.path.join('html', 'accounts', 'account_recovery.html')) def error(msg): return current_app.message(msg, url_for('forgot_pass')) try: user = g.notebook.user(request.values[username]) except KeyError: return error('Username is invalid.') if not user.is_email_confirmed(): return error("The e-mail address hasn't been confirmed.") #XXX: some of this could be factored out into a random passowrd #function. There are a few places in admin.py that also use it. from random import choice import string chara = string.letters + string.digits old_pass = user.password() password = ''.join([choice(chara) for i in range(8)]) user.set_password(password) from sagenb.notebook.smtpsend import send_mail from sagenb.notebook.register import build_password_msg # TODO: make this come from the server settings listenaddr = g.notebook.interface port = g.notebook.port fromaddr = 'no-reply@%s' % listenaddr body = build_password_msg(password, username, listenaddr, port, g.notebook.secure) destaddr = user.get_email() try: send_mail(fromaddr, destaddr, "Sage Notebook Account Recovery", body) except ValueError: # the email address is invalid user.set_password(old_pass) return error("The new password couldn't be sent."%destaddr) return current_app.message("A new password has been sent to your e-mail address.", url_for('base.index'))