def addadditionalusers(): player3 = User('player3', 'password', '*****@*****.**', "en", False, True) player4 = User('player4', 'password', '*****@*****.**', "en", False, True) db.session.add(player3) db.session.add(player4) db.session.commit() click.echo("Done")
def create(self, name, email) -> UserIDT: usr = User() usr.name = name usr.email = email self.session.add(usr) self.session.commit() return usr.id
def resolve_users(session, users_found: Dict): """ Resolve TSV names from DB names or emails. """ names = [x for x in users_found.keys()] emails = [x.get('email') for x in users_found.values()] User.find_users(session, names, emails, users_found) logger.info("Users Found for all TSVs = %s", users_found)
def addusers(): admin = User('admin', 'admin', '*****@*****.**', "en", True, True) pat = User('pat', 'password', '*****@*****.**', "en", False, True) player1 = User('player1', 'password', '*****@*****.**', "en", False, True) player2 = User('player2', 'password', '*****@*****.**', "en", False, True) db.session.add(admin) db.session.add(pat) db.session.add(player1) db.session.add(player2) db.session.commit() click.echo("Done")
def add_user(): for attribute in User.get_required_attributes(): if attribute not in request.json: return jsonify({ 'error': { 'msg': '\'' + attribute + '\' is required', 'code': 2, 'info': attribute } }), 400 if len(request.json['password']) < PASSWORD_MIN_LENGTH: return jsonify({ 'error': { 'msg': 'Password needs to be at least 8 characters long', 'code': 24 } }), 400 data = request.json username_exists = User.query.filter_by(username=data['username']).first() if username_exists: return jsonify({ 'error': { 'msg': 'Username ' + data['username'] + ' is already taken, please choose a different one', 'code': 24 } }), 409 email_exists = User.query.filter_by(email=data['email']).first() if email_exists: return jsonify({ 'error': { 'msg': 'There ia already a user registered with email ' + data['email'], 'code': 24 } }), 409 new_user = User(data['username'], data['password'], data['email'], data['language'], admin=False, active=True) db.session.add(new_user) db.session.commit() send_new_user_mail(new_user) return '', 201
def register(): # error = None if request.method == 'POST': username = request.form['username'].encode('utf-8').decode('latin1') password = request.form['password'] repw = request.form['prePassword'] # 验证用户名是否已存在 obj2 = DB.search_User(User, username) if obj2 == None: # 验证密码和确认密码是否一致 if password != repw: flash("密码和确认密码不一致!") return render_template('register.html') user = User(userName=username, password=password) DB.insert_into_table(user) return render_template('login.html') else: flash("用户名已存在!") return render_template('register.html')
def edit_user(user_id): user_id_from_token = get_jwt_identity() current_user = User.query.get(user_id_from_token) if not current_user.admin and user_id != user_id_from_token: return jsonify( {'error': { 'msg': 'Operation not permitted', 'code': 14 }}), 403 user = User.query.get(user_id) if not user: return jsonify( {'error': { 'msg': 'User not found', 'code': 16, 'info': user_id }}), 404 if "password" in request.json and not current_user.admin: if "oldPassword" not in request.json: return jsonify({ 'error': { 'msg': 'Current password must be provided as "oldPassword" within the request body', 'code': 21 } }), 400 if not user.verify_password(request.json["oldPassword"]): return jsonify( {'error': { 'msg': 'Password missmatch for user', 'code': 22 }}), 401 try: if "password" in request.json: if len(request.json['password']) < PASSWORD_MIN_LENGTH: return jsonify({ 'error': { 'msg': 'Password needs to be at least 8 characters long', 'code': 24 } }), 400 user.hash_password(request.json["password"]) del request.json["password"] for attribute in request.json: if attribute in User.get_protected_attributes( ) and not current_user.admin: db.session.rollback() return jsonify( {'error': { 'msg': 'Attribute protected', 'code': 23 }}), 400 if attribute in User.get_all_attributes(): setattr(user, attribute, request.json[attribute]) db.session.commit() return '', 204 except Exception: db.session.rollback() return jsonify({"error": { 'msg': "Failed to update user", 'code': 17 }}), 500