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): args = parser.parse_args() email = args['email'] password = args['password'] user = User().where([['email', '=', email]]).first() if user.exists() and bcrypt.check_password_hash( user.HIDDEN['password'], password): return response({ 'user': user.plus('token', user.generateToken()['jwt']).plus( 'admin', user.hasRole('admin')).data() }) return response( {'errors': ['Credentials do not match with our records.']}, 401)