def post(self): data = UserRegister.parser.parse_args() if UserModel.find_by_username(data['username']): return {"message": "A user with that username already exists"}, 400 user = UserModel(data['username'], data['password']) user.save_to_db() return {"message": "User created successfully."}, 201
def post(self): data = UserRegister.parser.parse_args() if UserModel.find_by_username(data['username']) return {'message': 'usernamen alreaduy exist'}, 400 user = UserModel(**data) user.save_to_db() return{'message': 'A user was created successfully'},201
def post(self): data = UserRegister.parser.parse_args() regex = '^(\w|\.|\_|\-)+[@](\w|\_|\-|\.)+[.]\w{2,3}$' if UserModel.find_by_user(data['username'], 'username'): return { 'status': 'failed', "message": "A user with that username already exists" }, 400 elif not re.search(regex, data['email']): return {'status': 'failed', "message": "Invalid Email"}, 400 elif data['password'] != data['passwordConfirm']: return {'status': 'failed', "message": " Password not match"}, 400 hashed = generate_password_hash(data['password'], method='sha256') time = datetime.now() user = UserModel( data['username'], data['email'], hashed, _id=UserModel.current_user() + 1, status="online", lastConnect=time.strftime('%Y-%m-%d %H:%M:%S'), picture= "https://firebasestorage.googleapis.com/v0/b/projectdoc-5af7b.appspot.com/o/template%2FArtboard%201.png?alt=media&token=b74d1752-21ae-4255-8d37-1440d1c967d5" ) print(user.json()) user.save_to_db() access_token = create_access_token(identity=user.userId, fresh=True, expires_delta=timedelta(hours=3)) refresh_token = create_refresh_token(user.userId) return make_response( { 'status': 'success', "data": { "userId": user.userId, "username": user.username, "permiss": user.permiss, "status": user.status, "picture": user.picture, "expires_token": time + timedelta(hours=3), "access_token": access_token, "refresh_token": refresh_token } }, 200)