def mutate(self, info, **kwargs): Validate.user_info(**kwargs) # password encryption kwargs['password'] = generate_password_hash(kwargs['password']) user = UserModal.save_user(**kwargs) token = Authentication.generate_token({ 'user_id': kwargs['user_id'], 'username': kwargs['username'], 'first_name': kwargs['first_name'], 'last_name': kwargs['last_name'], 'email': kwargs['email'], 'role': kwargs['role'] }) if type(user) == str: raise GraphQLError(user) return CreateUser(user=user, token=token)
def add_user(): user = User(request.json) db.session.add(user) try: db.session.commit() except exc.SQLAlchemyError as ex: app.logger.debug(ex) return "Error encountred", 500 return "Successfully user registered", 200
def edit_user_data(id): data = request.get_json() user = User.get_one_user(id) if not user: return jsonify({'message': 'User not found'}) user.update_user_info(data=data) return jsonify({'message': 'User data is updated'})
def delete_user(id): user = User.get_one_user(id) if not user: return jsonify({'message': 'User not found'}) user.delete_user() return jsonify({'message': "user deleted"})
def get_one_user_by_Id(id): user = User.get_one_user(id) if not user: return jsonify({'message': 'User not found'}) user_data = {} user_data['public_id'] = user.public_id user_data['name'] = user.name user_data['appeal_name'] = user.appealName # user_data['password'] = user.password return jsonify({'user': user_data})
def login(): data = request.get_json() user_name = data['name'] user = User.get_user_by_name(user_name) if not user: return jsonify({'message': 'No such user'}) if not user.check_hashed_password(data['password']): return jsonify({'message': 'No such user'}) token = Auth.generate_token(user.public_id) return jsonify({'token': token})
def get_all_user(): users = User.get_all_users() output_data = [] # print(users) for user in users: user_data = {} user_data['id'] = user.id user_data['public_id'] = user.public_id user_data['name'] = user.name user_data['appeal_name'] = user.appealName # user_data['password'] = user.password output_data.append(user_data) return jsonify({'users': output_data})
def create_user(): data = request.get_json() user_in_db = User.get_user_by_name(data.get('name')) if user_in_db: return jsonify({'message': 'User already exist'}) hashed_password = User.generate_hashed_password(data['password']) new_user = User(public_id=str(uuid.uuid4()), name=data['name'], appealName=data['appeal_name'], password=hashed_password) new_user.add_user() return jsonify({'message': 'success'})
def create(user_name, password, **kwargs): user = User(user_name=user_name, password=password) user.save()