示例#1
0
文件: site.py 项目: gerpayt/acgweb
def register():
    form = RegisterForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            if form.reqcode.data != config.REQCODE:
                form.reqcode.errors.append('邀请码错误')
            if Member.query.filter(Member.uid == form.username.data).count():
                form.username.errors.append('帐号已存在')
            if Member.query.filter(Member.email == form.email.data).count():
                form.email.errors.append('电子邮箱已存在')
            if Member.query.filter(Member.mobile_num == form.mobile_num.data).count():
                form.mobile_num.errors.append('手机号码已存在')
        if not form.errors:
            username = form.username.data
            password = form.password.data
            name = form.name.data
            email = form.email.data
            mobile = form.mobile_num.data
            _register(username, password, name, email, mobile)
            flash({'type': 'success', 'content': '注册成功,请登陆。'})
            if viewtype() == 1:
                return render_template('site/login_mobile.html', form=form)
            else:
                return render_template('site/login.html', form=form)
    if viewtype() == 1:
        return render_template('site/register_mobile.html', form=form)
    else:
        return render_template('site/register.html', form=form)
示例#2
0
文件: site.py 项目: camelshang/acgweb
def register():
    """Page: activity detail"""
    form = RegisterForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            if form.reqcode.data != config.REQCODE:
                form.reqcode.errors.append('邀请码错误')
            if Member.query.filter(Member.uid == form.username.data).count():
                form.username.errors.append('帐号已存在')
            if Member.query.filter(Member.email == form.email.data).count():
                form.email.errors.append('电子邮箱已存在')
            if Member.query.filter(Member.mobile_num == form.mobile_num.data).count():
                form.mobile_num.errors.append('手机号码已存在')
        if not form.errors:
            key = md5.new()
            key.update(form.password.data)
            member = Member()
            member.uid = form.username.data.upper()
            member.name = form.name.data
            member.password = key.hexdigest()
            member.email = form.email.data
            member.mobile_num = form.mobile_num.data
            member.type = 0
            member.update_register_time()
            member.update_lastlogin_time()
            db.session.add(member)
            db.session.commit()

            adminmember = Member.query.get(config.SYS_ADMIN)
            readmeurl = config.BASE_URL + url_for('articledetail', article_title=config.README_TITLE)
            admin_url = config.BASE_URL + url_for('memberdetail', member_uid=config.SYS_ADMIN)
            admin_name = adminmember.name
            subject = mail.register_tmpl['subject']
            content = mail.register_tmpl['content'] % (readmeurl, readmeurl, admin_url, admin_name)
            msg_id = mail.send_message(member.uid, config.SYS_ADMIN, subject, content, 2)
            mail.send_mail(subject, content, member.name, member.email,
                msgid=msg_id, touid=member.uid, uid=member.uid)

            flash({'type': 'success', 'content': '注册成功,请登陆。'})
            if viewtype() == 1:
                return render_template('site/login_mobile.html', form=form)
            else:
                return render_template('site/login.html', form=form)
    if viewtype() == 1:
        return render_template('site/register_mobile.html', form=form)
    else:
        return render_template('site/register.html', form=form)