Пример #1
0
    def get(self):
        args = request.args.to_dict()
        print(current_app)

        if 'username' in args:
            user = User.find_user_by_username(username=args['username'])

            if not user:
                return {
                    "message": "User not found id={}".format(args['id'])
                }, 404

            return json.loads(user.to_json())

        else:
            users = User.read()
            return json.loads(users.to_json())
Пример #2
0
    def post(self):
        args = request.args.to_dict()

        username = args['username']
        user = User.find_user_by_username(username)
        if not user:
            return jsonify({'message': 'User not found'}), 400

        code = generate_code()
        user.code = code
        user.save()

        html = render_template('reset.html', code=code, name=user.name)
        subject = "Restore password"
        message = Message(subject=subject,
                          html=html,
                          recipients=[user.username])
        send_email(message)

        return 200
Пример #3
0
    def post(self):
        form = request.form.to_dict()

        if not 'username' or not 'password' in form:
            return make_response(
                "Could not verify", 401,
                {"WWW-Authenticate": 'Basic realm="Login required!"'})

        user = User.find_user_by_username(form['username'])

        if not user:
            return make_response(
                "Could not verify", 401,
                {"WWW-Authenticate": 'Basic realm="Login required!"'})

        # if check_password_hash(user.password, form['password']):
        #     encoded_jwt = jwt.encode({"some": "payload"}, current_app.config['SECRET_KEY'], algorithm="HS256")
        #     print(encoded_jwt)
        #     token = jwt.encode({'_id': user._id}, current_app.config['SECRET_KEY'], algorithm="HS256")
        login_user(user)
        return json.loads(user.to_json())
Пример #4
0
    def get(self):
        args = request.args.to_dict()

        code = get_field("code", args)
        username = get_field("username", args)
        pwd = get_field("pwd", args)

        user = User.find_user_by_username(username)

        if code != None and pwd != None:
            code = int(code)
            print(user.code, code)
            if not code == user.code:
                return {'message': 'Code isn\'t correct'}, 401
            user.refresh_token()
            user = User.update(str(user.id), {'password': pwd})
            login_user(user)
            return {'token': user.token}, 200
        elif code != None:
            code = int(code)
            if code != user.code:
                return {'message': 'Code isn\'t correct'}, 401
            return {'message': 'Code is correct'}, 200
        return {'message': 'Some server errors, cheers :)'}, 500