def register_p():
    username = request.form.get('username')
    pwd1 = request.form.get('pwd1')
    pwd2 = request.form.get('pwd2')
    img_file = request.files.get('avatar')
    company = request.form.get('company')
    weibo = request.form.get('weibo')
    job = request.form.get('job')
    we_chat = request.form.get('we_chat')
    e_mail = request.form.get('e_mail')
    we_public = request.form.get('we_public')
    info = request.form.get('info')
    if not all([username, pwd1, pwd2]):
        return '请填写必填字段'
    if pwd1 != pwd2:
        return '两次输入的密码不符合'
    user = User.query.filter_by(name=username).first()
    if user:
        return '该用户名已经存在'
    else:
        user = User()
        user.name = username
        user.password = pwd1
        image_path = os.path.join(UPLOAD_DIR, img_file.filename)
        img_file.save(image_path)
        user.avatar = os.path.join('upload', img_file.filename)
        user.company = company
        user.weibo = weibo
        user.job = job
        user.we_chat = we_chat
        user.e_mail = e_mail
        user.info = info
        try:
            user.add_update()
        except Exception as e:
            db.session.rollback()
            return '创建用户失败'
        return redirect(url_for('user.login_g'))
Exemple #2
0
 def test_avatar(self):
     u = User(username='******', email='*****@*****.**')
     self.assertEqual(u.avatar(128), ('https://www.gravatar.com/avatar/'
                                      'd4c74594d841139328695756648b6bd6'
                                      '?d=identicon&s=128'))