<reponame>Mrdorom/cloudAutoServer<gh_stars>0
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time : 2020/8/20 18:27
# @Author : dorom
# @File : login_user.py
# @Software: PyCharm

try:
    from flask.ext.restful import Api, Resource,fields,marshal_with
except:
    from flask_restful import Api,Resource,fields,marshal_with

from flask import jsonify
from apps.auth.models.users_models import User
from apps.auth.schema.user_schema import LoginSerailizer
from flask_jwt_extended import  create_access_token,create_refresh_token


class Login(Resource):

    def __init__(self):
        self.login_serailzer = LoginSerailizer()

    def post(self):
        """
        登录接口
        @param email
        @:param password
        @response:
        {
          "code": 200,
          "res": {
                "token": "<KEY>"
          },
          "message": "登录成功"
        }
        :return:
        """
        parser_args = self.login_serailzer.login_parser().parse_args()
        email = parser_args.get('email')
        password = parser_args.get('password')
        queryset = User.query.filter_by(email=email).first()
        if queryset:
            status_verify = queryset.verify_password(password)   #hash 密码校验
            if  status_verify:
                access_token = create_access_token(identity=queryset.id, fresh=True)
                refresh_token = create_access_token(queryset.id)   # 生成秘钥
                res = {
                    "code":200,
                    "res":{"access_token":access_token,
                           "refresh_token": refresh_token},
                    "message":"登录成功"
                }
                return jsonify(res)

        res = {
            "code": 500,
            "res": {},
            "message": "账号密码是错误"
        }
        return jsonify(res)
#!/usr/bin/env python
# -*- coding:utf-8 -*-
# @Time : 2020/8/20 18:27
# @Author : dorom
# @File : login_user.py
# @Software: PyCharm

try:
    from flask.ext.restful import Api, Resource,fields,marshal_with
except:
    from flask_restful import Api,Resource,fields,marshal_with

from flask import jsonify
from apps.auth.models.users_models import User
from apps.auth.schema.user_schema import LoginSerailizer
from flask_jwt_extended import  create_access_token,create_refresh_token


class Login(Resource):

    def __init__(self):
        self.login_serailzer = LoginSerailizer()

    def post(self):
        """
        登录接口
        @param email
        @:param password
        @response:
        {
          "code": 200,
          "res": {
                "token": "<KEY>"
          },
          "message": "登录成功"
        }
        :return:
        """
        parser_args = self.login_serailzer.login_parser().parse_args()
        email = parser_args.get('email')
        password = parser_args.get('password')
        queryset = User.query.filter_by(email=email).first()
        if queryset:
            status_verify = queryset.verify_password(password)   #hash 密码校验
            if  status_verify:
                access_token = create_access_token(identity=queryset.id, fresh=True)
                refresh_token = create_access_token(queryset.id)   # 生成秘钥
                res = {
                    "code":200,
                    "res":{"access_token":access_token,
                           "refresh_token": refresh_token},
                    "message":"登录成功"
                }
                return jsonify(res)

        res = {
            "code": 500,
            "res": {},
            "message": "账号密码是错误"
        }
        return jsonify(res)
#!/usr/bin/env python # -*- coding:utf-8 -*- # @Time : 2020/8/20 18:27 # @Author : dorom # @File : login_user.py # @Software: PyCharm 登录接口         @param email         @:param password         @response:         {           "code": 200,           "res": {                 "token": "<KEY>"           },           "message": "登录成功"         }         :return: #hash 密码校验 # 生成秘钥