def _post_register(): redirect_to = request.args.get("redirect_to") values = get_form_values(request, _get_registration_form()) dic = {k: v for k, v in values.iteritems()} del dic["cfm_password"] del dic["password"] user_obj = users.User( **dic ) user_obj.account_status = users.AccountStatus.AWAITING_CONFIRMATION if not users.get_user_by_attr({ "$or": [{ "email": user_obj.email }, { "username": user_obj.username }] }): user_obj._id = users.save(user_obj, need_confirmation=False, confirmation_email_subject="Complete your account registration", confirmation_relative_url="/register/confirm/") users.set_passwd(user_obj, values["password"]) return redirect(redirect_to) login_user(user_obj) return redirect(url_for("register_user") + "?user=exists")
def register(): if request.method == "GET": registration_form = generate_form(__get_registration_form(), **{ "action": "/register/", "method": "post", }) return render_template("registration.html", **{ "registration_form": registration_form, "is_register": True, }) else: values = get_form_values(request, __get_registration_form()) dic = {k: v for k, v in values.iteritems()} user_obj = users.User( **dic ) user_obj.account_status = users.AccountStatus.AWAITING_CONFIRMATION if not users.get_user_by_attr({ "$or": [{ "email": user_obj.email }, { "username": user_obj.username }] }): user_obj = users.save(user_obj, need_confirmation=True, confirmation_email_subject="Complete your account registration", confirmation_relative_url="/register/confirm/") users.set_passwd(user_obj, values["password"]) return "Saved!" return "Already registered."
def new_user(_id, address, email, first_name, last_name, middle_name, password, status, user_groups, username): u = users.User() if _id is not None: u = users.get(_id) u.username = username u.first_name = first_name u.middle_name = middle_name u.last_name = last_name u.email = email u.address = address u.groups = user_groups if user_groups is not None else [] u.account_status = status u._id = u.save() if len(password) > 0: users.set_passwd(u, password)
def reset_password(user_id, token): user_obj = users.get(user_id) if users.check_token(user_obj, users.AccountActivity.RESET_PASSWORD, token): #show passwd reset form if request.method == "GET": form = __passwd_reset_form() return render_template("passwd_reset.html", **{ "form": generate_form(form, **{ "method": "post" }), }) #parse reset form else: values = get_form_values(request, __passwd_reset_form()) new_passwd = values["passwd"] users.set_passwd(user_obj, new_passwd) users.remove_token(user_obj, users.AccountActivity.RESET_PASSWORD) return "Changed password!" return "Fail!"