Пример #1
0
def register():
    form = RegisterForm()
    if form.validate_on_submit():
        email = request.form.get('email')
        username = request.form.get('username')
        password = request.form.get('password')
        confirm_password = request.form.get('confirm')
        if password != confirm_password:
            flash('两次输入的密码不一致~')
            return render_template('register.html', form=form)

        db = DBOperator()
        if db.query_user_by_email(Users, email):
            flash('该邮箱已经注册~')
            return render_template('register.html', form=form)

        if db.query_user_by_name(Users, username):
            flash('该用户名已经存在~')
            return render_template('register.html', form=form)

        user = Users(email=email, username=username, password=get_md5(password), create_time=get_current_time(),
                     delete_flag=0, avatar=AVATARS[random.randint(0, len(AVATARS)-1)])
        db.add_data(user)
        db.commit_data()
        db.clear_buffer()
        del db
        token = generate_token(user=user, operation='confirm')
        send_confirm_email(user=user, token=token)
        return redirect(url_for('login_bp.user_login'))
    return render_template('register.html', form=form)
Пример #2
0
    def post(self):

        args = parser.parse(signup_args, request)
        if User.objects(username=args['email']):
            return api_abort(422, "Eamil已注册")
        elif User.objects(username=args['username']):
            return api_abort(422, "用户名已存在")
        try:
            u = User(
                email=args["email"].lower(),
                username=args["username"],
                # TODO: nginx
                avatar='http://192.168.1.106:8000/avatar/r{0}.png'.format(
                    random.randint(1, 10)))
            u.set_password(args["password"])
            u.save()
            if os.getenv('FLASK_ENV') == 'development':
                # 发送 email
                uid = User.objects(email=args['email']).first().id
                send_confirm_email(args['email'], args['username'],
                                   generate_token(uid))
            return '', 201
        except Exception as e:
            current_app.logger.error(e)
            return api_abort(500)
Пример #3
0
def inform_email(name, email):
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    user = User.query.filter_by(email=email).first()
    if user:
        send_confirm_email(user)
    return name + ' ' + email
Пример #4
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user is None or not user.check_password(form.password.data):
            flash('Invalid username or password', category='danger')
            return redirect(url_for('login'))
        if not user.confirmed:
            send_confirm_email(user)
            flash('Please check your email and confirm that you own it!',
                  category='warning')
            return redirect(url_for('login'))
        tz = Timezone.query.filter_by(name=form.timezone.data).first()
        if not tz:
            tz = Timezone(name=form.timezone.data)
            db.session.add(tz)
            db.session.commit()  # we need to commit before using tz.id
        user.tz_id = tz.id
        db.session.add(user)
        db.session.commit()
        login_user(user, remember=form.remember_me.data)
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('index')
        return redirect(next_page)
    return render_template('login.html',
                           title='Sign In',
                           form=form,
                           tzcode=True)
Пример #5
0
def resend_confirm_mail():
    db = DBOperator()
    user = db.query_filter_by_id(Users, condition=g.normal_user)[0]
    token = generate_token(user=user, operation=Operations.CONFIRM)
    send_confirm_email(user=user, token=token)
    flash('邮箱认证邮件发送成功,请前往邮箱查看认证!', 'success')
    return redirect(url_for('index_bp.index'))
Пример #6
0
def resend_confirm_email():
    if current_user.comfirmed:
        return redirect(url_for('main.index'))

    token = generate_token(user=current_user, operation=Operations.CONFIRM)
    send_confirm_email(user=current_user, token=token)
    flash('新邮件已经发送,请前往确认', 'info')
    return redirect(url_for('main.index'))
Пример #7
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        username=form.username.data
        email=form.email.data
        send_confirm_email(username, email)
        flash('Verifique sua caixa de e-mails para confirmar seu cadastro')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
Пример #8
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.index'))

    form = RegisterForm()
    if form.validate_on_submit():
        name = form.name.data
        email = form.email.data.lower()
        username = form.username.data
        password = form.password.data
        user = User(name=name, email=email, username=username)
        user.set_password(password)
        db.session.add(user)
        db.session.commit()
        token = generate_token(user=user, operation='confirm')
        send_confirm_email(user=user, token=token)
        flash('恭喜!你已经成功注册!', 'info')
        return redirect(url_for('.login'))
    return render_template('auth/register.html', form=form)
Пример #9
0
def register(parent):
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data.lower())
        user.set_password(form.password.data)
        user.lunch_time = form.lunch_time.data
        user.site = form.site.data.title()
        user.canteen = form.canteen.data.title()
        user.confirmed = False
        master = User.query.filter_by(username=parent).first()
        if master: user.followed.append(master)  # yes, just an ugly hack
        db.session.add(user)
        db.session.commit()
        send_confirm_email(user)
        flash('Please check your email and confirm that you own it!',
              category='warning')
        return redirect(url_for('login'))
    elif request.method == 'GET':
        form.invite_me.data = True
        form.lunch_time.data = time(hour=11, minute=45)
    return render_template('register.html', title='Register', form=form)
Пример #10
0
def postCode(id):
    try:
        user = User.query.get(id)

        if(user):
            code = UserCode.query.filter_by(user_id=user.id).first()

            if(code == None):
                code = UserCode(user_id=id)
                code.gen_code()

            while UserCode.query.filter_by(code = code.code).first():
                code.gen_code()

            db.session.add(code)
            db.session.commit()

            send_confirm_email(user, code.code)
        else:
            return jsonify({ "Error" : "User not found" })

        return jsonify({"Success" : "An email with your registration code has been sent"})
    except:
        return jsonify({"Error" : "There was an error sending your code"})
Пример #11
0
def send_test_mail():
    user = User.q
    send_confirm_email(user, code.code)
    return jsonify({ "result" : "thing" })