def change_nickname(): """Function, used to change user nickname. :rtype: JSON :request agrs: `{id: "6", nickname: "newnickname"}` :return: :statuscode 400: request is invalid :statuscode 200: nickname was successfully changed """ response = jsonify(), 400 if request.method == 'POST' and request.get_json(): data = request.get_json() valid = validator.change_nickname(data) user = ecomap_user.get_user_by_id(data['id']) if valid['status']: if user: user.change_nickname(data['nickname']) response = jsonify(), 200 else: response = jsonify(), 400 else: response = Response(json.dumps(valid), mimetype='application/json'), 400 return response
def get_user_info(user_id): """This method returns json object with user data. :param user_id: id of user for viewing detailed info :rtype: JSON :return: - If user exists and data provided: ``{"avatar": "/uploads/user_profile/userid_6/profile_id6.png", "email": "*****@*****.**", "name": "Firstname", "role": "admin", "surname": "Lastname", "nickname": "nick"}`` - If there is no user with given email: ``{status:'There is no user with given email'}`` :statuscode 401: there is no user with given email :statuscode 200: user exists and data provided """ if request.method == 'GET': user = ecomap_user.get_user_by_id(user_id) if user: return jsonify(name=user.first_name, surname=user.last_name, nickname=user.nickname, email=user.email, role=user.role, avatar=user.avatar) else: return jsonify(status='There is no user with given email'), 401
def change_password(): """Function, used to change user password. :rtype: JSON :request agrs: `{id: "6", old_pass: "******", password: "******"}` :return: :statuscode 400: request is invalid or old password not confirmed :statuscode 200: password was successfully changed """ response = jsonify(), 400 if request.method == 'POST' and request.get_json(): data = request.get_json() valid = validator.change_password(data) if valid['status']: user = ecomap_user.get_user_by_id(data['id']) if user and user.verify_password(data['old_pass']): user.change_password(data['password']) response = jsonify(), 200 else: response = jsonify(), 400 else: response = Response(json.dumps(valid), mimetype='application/json'), 400 return response
def find_to_delete(): """Function to send email with delete link""" data = request.get_json() search_id = data['user_id'] user = ecomap_user.get_user_by_id(search_id) if search_id == ecomap_user.User.get_id(user): ecomap_user.delete_user(user) response = jsonify(message='Email was sended.'), 200 else: response = jsonify(error="You can't do that"), 400 return response
def get_user_info(user_id): """This method returns json object with user data.""" if request.method == 'GET': user = ecomap_user.get_user_by_id(user_id) if user: return jsonify(name=user.first_name, surname=user.last_name, email=user.email, role=user.role, avatar=user.avatar) else: return jsonify(status='There is no user with given email'), 401
def change_password(): """Function, used to change user password :return: response - json object. """ response = jsonify(), 400 if request.method == 'POST' and request.get_json(): data = request.get_json() valid = validator.change_password(data) if valid['status']: user = ecomap_user.get_user_by_id(data['id']) if user and user.verify_password(data['old_pass']): user.change_password(data['password']) response = jsonify(), 200 else: response = jsonify(), 400 else: response = Response(json.dumps(valid), mimetype='application/json'), 400 return response