Esempio n. 1
0
def user_bind():
    verify_code = int(request_value(request, 'code'))
    pwd = request_value(request, 'pwd')
    email = request_value(request, 'email').strip()
    username = request_value(request, 'username').strip()

    auth, user_id, pass_email, auth_username = RGUIController.do_auth_more_info(
        need_request_email=False)
    if not auth or username != auth_username:
        return jsonify(form_res(RGResCode.auth_fail))

    uid, res = user.verify_user(username=username,
                                email=email,
                                pwd=pwd,
                                verify_code=verify_code,
                                verify_type=RGVerifyType.bind)

    if uid is not None:
        token = RGUIController.token_session(uid=uid,
                                             token_type=session['type'],
                                             username=username,
                                             email=email,
                                             remember=None)
        return jsonify(form_res(RGResCode.ok, {'token': token}))
    else:
        return jsonify(form_res(res, None))
Esempio n. 2
0
def bind_page():
    if not RGUIController.user_need_to_bind_page():
        return redirect(url_for('login_page'))
    auth, user_id, email, username = RGUIController.do_auth_more_info(
        need_request_email=False)
    return RGUIController.ui_render_template(
        "login.html", **{
            'username': username,
            'coll_email': True,
            'verify_type': RGVerifyType.bind
        })
Esempio n. 3
0
def get_verify_code():
    username = request_value(request, 'username').strip()
    email = request_value(request, 'email').strip()
    verify_type = int(request_value(request, 'verifyType', default='0'))

    if verify_type == RGVerifyType.bind:
        auth, user_id, pass_email, auth_username = RGUIController.do_auth_more_info(
            need_request_email=False)
        if auth is False or username != auth_username:
            return jsonify(form_res(RGResCode.auth_fail))

    verify_code = user.generate_verify_code()

    res = user.new_user_and_save_verify_code(username=username,
                                             email=email,
                                             verify_code=verify_code,
                                             verify_type=verify_type)

    if res == RGResCode.ok:
        try:
            if verify_type == RGVerifyType.forget_pwd:
                title = RGMailConfig['newPasswordUserMailTitle']
                content = RGMailConfig[
                    'newPasswordVerifyCodeMailFormat'].format(verify_code)
            else:
                title = RGMailConfig['newUserMailTitle']
                content = RGMailConfig['bindVerifyCodeMailFormat'].format(
                    verify_code)

            send_verify_mail(receiver=email, title=title, content=content)
            return jsonify(form_res(RGResCode.ok))
        except Exception as e:
            print(e)
            user.update_user_info(username=username, info_payload='')
            return jsonify(form_res(RGResCode.server_error))
    return jsonify(form_res(res))