Exemplo n.º 1
0
def memberedit(member_uid=''):

    if request.method == 'POST':
        form = MemberForm(request.form)
        if form.validate_on_submit():
            if not member_uid and Member.query.filter(Member.uid == form.uid.data).count():
                form.uid.errors.append('学号已存在')
            if Member.query.filter(Member.email == form.email.data, Member.uid != member_uid).count():
                form.email.errors.append('电子邮箱已存在')
            if Member.query.filter(Member.mobile_num == form.mobile_num.data, Member.uid != member_uid).count():
                form.mobile_num.errors.append('手机号码已存在')

        if not form.errors:
            member = Member.query.get(member_uid)
            if not session.get('is_arra_monitor'):
                abort(403)
            if not member:
                member = Member()
                member.uid = form.uid.data
                key = md5.new()
                key.update(form.mobile_num.data)
                member.password = key.hexdigest()
                member.update_register_time()
                member.update_lastlogin_time()
            else:
                member.uid = member_uid
            member.name = form.name.data
            member.sex = form.sex.data
            member.school = form.school.data.replace(' ', '')
            member.mobile_num = form.mobile_num.data.replace(' ', '')
            member.mobile_type = form.mobile_type.data
            member.mobile_short = form.mobile_short.data.replace(' ', '')
            member.qqnum = form.qqnum.data.replace(' ', '')
            member.email = form.email.data.replace(' ', '')
            member.address = form.address.data.replace(' ', '')
            member.credit_card = form.credit_card.data.replace(' ', '')
            member.type = form.type.data
            member.introduce = form.introduce.data
            db.session.add(member)
            db.session.commit()

            flash({'type': 'success', 'content': '保存成功!'})
            return redirect('/membermanage')
        return render_template('member/memberedit.html', form=form, member_uid=member_uid)
    else:
        member = Member.query.get(member_uid)
        if not session.get('is_arra_monitor'):
            abort(403)
        form = MemberForm(obj=member)

        return render_template('member/memberedit.html', form=form, member_uid=member_uid)
Exemplo n.º 2
0
def _register(username, password, name, email, mobile):
    key = md5.new()
    key.update(password)
    member = Member()
    member.uid = username.upper().replace(' ', '')
    member.name = name.replace(' ', '')
    member.password = key.hexdigest()
    member.email = email.replace(' ', '')
    member.mobile_num = mobile.replace(' ', '')
    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)
Exemplo n.º 3
0
def myinfoapi():
    uid = request.args.get('uid')
    if request.method == 'POST':
        member = Member.query.get(uid)
        form = MemberForm(request.form)
        if form.validate_on_submit():
            if Member.query.filter(Member.email == form.email.data, Member.uid != uid).count():
                form.email.errors.append('电子邮箱已存在')
            if Member.query.filter(Member.mobile_num == form.mobile_num.data, Member.uid != uid).count():
                form.mobile_num.errors.append('手机号码已存在')

        if not form.errors:
            if member and member.uid != uid:
                abort(403)
            if not member: member = Member()
            member.uid = uid
            member.name = form.name.data
            member.sex = form.sex.data
            member.school = form.school.data
            member.mobile_num = form.mobile_num.data
            member.mobile_type = form.mobile_type.data
            member.mobile_short = form.mobile_short.data
            member.qqnum = form.qqnum.data
            member.email = form.email.data
            member.address = form.address.data
            member.credit_card = form.credit_card.data
            member.introduce = form.introduce.data
            session['name'] = member.name
            db.session.add(member)
            db.session.commit()

            flash({'type': 'success', 'content': '保存成功!'})
            return redirect('/myinfo')

    else:
        member = Member.query.get(uid)
        form = MemberForm(obj=member)

        res = {}
        res['uid'] = member.uid
        res['name'] = member.name
        res['type'] = member.type
        res['sex'] = member.sex
        res['school'] = member.school
        res['mobile'] = member.mobile_num
        res['mobile_type'] = member.mobile_type
        res['mobile_short'] = member.mobile_short
        res['email'] = member.email
        res['qqnum'] = member.qqnum
        res['address'] = member.address
        res['credit_card'] = member.credit_card
        res['introduce'] = member.introduce
        res['photo'] = member.photo
        res['register_time'] = member.register_time
        res['lastlogin_time'] = member.lastlogin_time

        resp = make_response(json.dumps(res))
        resp.headers['Access-Control-Allow-Origin'] = '*'
        return resp
Exemplo n.º 4
0
def myinfo():
    if request.method == 'POST':
        member = Member.query.get_or_404(session['uid'])
        form = MemberForm(request.form)
        if form.validate_on_submit():
            if Member.query.filter(Member.email == form.email.data, Member.uid != session[u'uid']).count():
                form.email.errors.append('电子邮箱已存在')
            if Member.query.filter(Member.mobile_num == form.mobile_num.data, Member.uid != session[u'uid']).count():
                form.mobile_num.errors.append('手机号码已存在')

        if not form.errors:
            if member and member.uid != session[u'uid']:
                abort(403)
            if not member: member = Member()
            member.uid = session[u'uid']
            member.name = form.name.data
            member.sex = form.sex.data
            member.school = form.school.data
            member.mobile_num = form.mobile_num.data
            member.mobile_type = form.mobile_type.data
            member.mobile_short = form.mobile_short.data
            member.qqnum = form.qqnum.data
            member.email = form.email.data
            member.address = form.address.data
            member.credit_card = form.credit_card.data
            member.introduce = form.introduce.data
            session['name'] = member.name
            db.session.add(member)
            db.session.commit()

            flash({'type': 'success', 'content': '保存成功!'})
            return redirect('/myinfo')
        #print form.errors
        if viewtype() == 1:
            return render_template('my/myinfo_mobile.html', form=form, member=member)
        else:
            return render_template('my/myinfo.html', form=form, member=member)
    else:
        member = Member.query.get_or_404(session['uid'])
        if member.uid != session[u'uid']:
            abort(403)
        form = MemberForm(obj=member)

        if viewtype() == 1:
            return render_template('my/myinfo_mobile.html', form=form, member=member)
        else:
            return render_template('my/myinfo.html', form=form, member=member)
Exemplo n.º 5
0
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)