def post(self): args = parser.parse_args() user_id = get_jwt_identity()['id'] # Check if passwords are the same if args['password'] is not None and args['passwordConfirm'] != args[ 'password']: return response( {'errors': ['Password and Confirm Password must be same']}, 400) # Check if the email is already taken or not email = args['email'] user = User().where('email', email).first() if user.exists() and user.ATTRIBUTES['id'] != user_id: return response({'errors': ['This email is already taken']}, 400) # Update user user = User().where('id', '=', user_id).first() if user.exists() is True: user.update({ 'name': args['name'], 'email': args['email'], 'slug': user.generateSlug(name=args['name']), 'password': bcrypt.generate_password_hash(args['password']).decode('utf-8') }) return response({'user': user.data()}) return response({'errors': ['User could not found']}, 404)
def post(self): args = parser.parse_args() password = args['password'] password_confirm = args['passwordConfirm'] if password != password_confirm: return response({'errors': ['Passwords do not match']}, 401) # Rule 2 user = User() user.create({ 'name': args['name'], 'email': args['email'], 'password': bcrypt.generate_password_hash(args['password']).decode('utf-8'), 'slug': user.generateSlug(args['name']) }) if user.validate() is False: return response({'errors': user.getErrors()}, 401) user.save() return response({ 'user': user.plus('token', user.generateToken()['jwt']).plus( 'admin', user.hasRole('admin')).data() })
def post(self, user_id): args = parser.parse_args() # Check if the email is already taken or not email = args['email'] user = User().where('email', email).first() if user.exists() and user.ATTRIBUTES['id'] != user_id: return response({ 'errors': 'This email is already taken' }, 400) # Update user user = User().where('id', '=', user_id).first() if user.exists() is True: user.update({ 'name': args['name'], 'email': args['email'], 'slug': user.generateSlug(name=args['name']), }) return response({ 'user': user.data() }) return response({ 'errors': [ 'User could not found' ] }, 404)