def register(): if request.method == 'GET': return render_template('register.html') else: print(request.form) print(dict(request.form)) username = request.form.get('username') paw = request.form.get('password') rpaw = request.form.get('repassword') phone = request.form.get('phone') if username: print('aaaa') if paw: print('bbb') if paw == rpaw: user = User() user.username = username user.password = paw user.phone = phone db.session.add(user) db.session.commit() # user.save() return redirect(url_for('user.index')) else: return '密码不一致'
def post(self): args = parse.parse_args() username = args.get('username') password = args.get('password') hobby = args.get('hobby') print(hobby) user = User() user.username = username user.password = password db.session.add(user) db.session.commit() return user
def register(): username = request.json.get('username') password = request.json.get('password') if username is None or password is None: abort(400) # missing arguments if User.query.filter_by(username=username).first() is not None: abort(400) # existing user user = User(username=username) user.hash_password(password) db.session.add(user) db.session.commit() return jsonify({'username': user.username}), 201, {'Location': url_for('user.get_user', id=user.id, _external=True)}
def user_register(): if request.method == 'POST': username = request.form.get('username') phone = request.form.get('phone') password = request.form.get('password') re_password = request.form.get('repassword') if password == re_password: user = User() user.username = username user.password = generate_password_hash(password) user.phone = phone db.session.add(user) # 将user对象添加到session缓存 db.session.commit() return redirect(url_for('user.login')) return render_template('user/register.html')
def register(): if request.method == 'POST': username = request.form.get('username') password = request.form.get('password') repassword = request.form.get('repassword') phone = request.form.get('phone') if password == repassword: for item in users: if item.username == username: return render_template('user/register.html', msg='用户已存在') user = User() user.username = username user.password = password user.phone = phone db.session.add(user) db.session.commit() return redirect('/') return render_template('user/register.html')
def verify_password(username_or_token, password): from apps.user.model import User # first try to authenticate by token user = User.verify_auth_token(username_or_token) if not user: user = User.query.filter_by(username=username_or_token).first() if not user or not user.verify_password(password): return False g.user = user return True
def register(): print(request.method) if request.method == "POST": form = request.form username = form.get("username") password = form.get("password") repassword = form.get("repassword") phone = form.get("phone") if password == repassword: user = User() user.username = username user.password = password user.phone = phone db.session.add(user) db.session.commit() return "用户注册成功" else: return "两次密码不一致" else: return render_template('user/register.html')
def post(self): """ * 注册用户: * 请求:{userName:'******',nickName:'xx',pwd:'1234567',checkPwd:'1234567'} * 响应:{token:'12345678'} """ form = UserForm(data=request.json) if form.validate(): user = User(**form.data) try: db.session.add(user) token = Token.encryptTk(current_app.config, user.to_dict()) db.session.commit() except: db.session.rollback() return {'code': RET.SERVERERR, 'msg': error_map[RET.SERVERERR]} if not token: return {'code': RET.SERVERERR, 'msg': error_map[RET.SERVERERR]} return {'code': RET.OK, 'msg': 'OK', 'data': {'token': token}} return {'code': RET.PARAMERR, 'msg': getFlatten(form.errors.values())}
def register(): if request.method == "POST": form = request.form username = form.get("username") password = form.get("password") repassword = form.get("repassword") phone = form.get("phone") if password == repassword: # 注册用户 user = User() user.username = username user.password = hashlib.sha256( password.encode('utf-8')).hexdigest() user.phone = phone db.session.add(user) db.session.commit() return redirect(url_for('user.home')) else: return "两次密码不一致" else: return render_template('user/register.html')
def post(self): # 获取数据 args = parser.parse_args() username = args.get('username') password = args.get('password') phone = args.get('phone') bobby = args.get('hobby') print(bobby) icon = args.get('icon') print(icon) # 创建user对象 user = User() user.username = username user.password = password if icon: upload_path = os.path.join(Config.UPLOAD_ICON_DIR, icon.filename) icon.save(upload_path) # 保存路径个 user.icon = os.path.join('upload/icon', icon.filename) if phone: user.phone = phone db.session.add(user) db.session.commit() return user
def register(): if request.method == 'POST': username = request.form.get('username') pwd = request.form.get('pwd') repwd = request.form.get('cpwd') phone = request.form.get('phone') select_user = User.query.filter(User.username == username).all() if len(select_user) == 0: if pwd == repwd: user = User() user.username = username user.pwd = generate_password_hash(pwd) user.phone = phone db.session.add(user) db.session.commit() return redirect(url_for('user.login')) else: return '密码不一致' return render_template('user/register.html', msg='用户名已存在') return render_template('user/register.html')
def register_blueprint(): """ :return: response """ if request.method == 'POST': # 将前端页面的数据传回后台 username = request.form.get('username') password = request.form.get('password') repassword = request.form.get('repassword') phone = request.form.get('phone') # 判断如果两次密码一致,则创建User对象 if password == repassword: # 使用model持久化的方式存储数据 user_db = User() user = user_db.query.filter_by(username=username).all() # 判断用户名唯一性 if user: return render_template('user/register.html', msg='用户名已存在!') user_db.username = username user_db.password = hashlib.sha256(password.encode('utf-8')).hexdigest() # 密码加密 user_db.phone = phone # 将一条数据添加入数据库中,session相当于缓存 db.session.add(user_db) db.session.commit() # # 使用列表的方式存储数据 # user = User_value(username, password, phone) # # 将user对象加入users列表中 # users.append(user) # print(url_for('user.center')) # 反响解析 return redirect(url_for('user.center')) else: return render_template('user/register.html', msg='两次密码不一致!') return render_template('user/register.html')
def register(): if request.method == 'POST': username = request.form.get('username') password = request.form.get('password') repassword = request.form.get('repassword') phone = request.form.get('phone') if password == repassword: # 注册用户 # 1. 找到模型类并创建对象 user = User() # 2. 给对象的属性赋值 user.username = username user.password = hashlib.sha256( password.encode('utf-8')).hexdigest() user.phone = phone # 添加并提交 # 3.将user对象添加到session中(类似缓存) db.session.add(user) # 4.提交数据 db.session.commit() return redirect(url_for('user.user_center')) else: return '两次密码不一致!' return render_template('user/register.html')
def register(): if request.method == 'POST': # 获取post提交的数据 username = request.form.get('username') password = request.form.get('password') phone = request.form.get('phone') repassword = request.form.get('repassword') if password == repassword: # 用户名唯一 for user in users: if user.username == username: return render_template('user/register.html', msg='用户名已存在') # 创建user对象 user = User(username, password, phone) # 添加到用户列表 users.append(user) return redirect('/') return render_template('user/register.html')
def post(self): args = parser.parse_args() username = args.get('username') password = args.get('password') phone = args.get('phone') hobby = args.get('hobby') icon = args.get('icon') user = User() if icon: upload_path = os.path.join(config.UPLOAD_ICON_DIR, icon.filename) icon.save(upload_path) user.icon = config.UPLOAD_ICON_DIR + '\\' + icon.filename user.username = username user.password = password user.phone = phone db.session.add(user) db.session.commit() return user
def post(self): # 获取数据 args = parser.parse_args() username = args.get('username') password = args.get('password') phone = args.get('phone') hobby = args.get('hobby') # ['篮球', '皮球'] icon = args.get('icon') # <FileStorage: 'gjjxj.jpg' ('image/jpeg')> # 创建user对象 user = User() user.username = username user.password = password if icon: upload_path = os.path.join(Config.UPLOAD_ICON_DIR, icon.filename) icon.save(upload_path) # 保存路径 user.icon = os.path.join('upload', 'icon', icon.filename) if phone: user.phone = phone db.session.add(user) db.session.commit() return user