huskar_api/api/auth.py
def post(self):
        """Obtains an user token by checking username and password.

        :form username: Required. The username of user.
        :form password: Required. The password of user.
        :form expiration: Optional. The life time in seconds of the token.
                          ``0`` or omitted will make token be expired in 30
                          days. Default is ``0``.
        :<header Content-Type: :mimetype:`application/x-www-form-urlencoded`
        :status 400: The username or password is incorrect.
        :status 200: You could find token from the response body:
                     ``{"status": "SUCCESS", "data": {"token": "..",
                     "expires_in": 1}}``
        """
        username = request.form['username'].strip()
        password = request.form['password'].strip()
        expires_in = request.form.get('expiration', type=int, default=0)
        if expires_in > 0:
            expires_in = min(expires_in, settings.ADMIN_MAX_EXPIRATION)
        else:
            expires_in = settings.ADMIN_MAX_EXPIRATION

        user = User.get_by_name(username)
        if user is None or user.is_application:
            raise UserNotExistedError('user not found')
        if not user.check_password(password):
            raise LoginError("username or password not correct")

        g.auth = SessionAuth.from_user(user)
        with audit_log(audit_log.types.OBTAIN_USER_TOKEN, user=user):
            token = user.generate_token(settings.SECRET_KEY, expires_in)
            return api_response({'token': token, 'expires_in': expires_in})
Obtains an user token by checking username and password.

        :form username: Required. The username of user.
        :form password: Required. The password of user.
        :form expiration: Optional. The life time in seconds of the token.
                          ``0`` or omitted will make token be expired in 30
                          days. Default is ``0``.
        :<header Content-Type: :mimetype:`application/x-www-form-urlencoded`
        :status 400: The username or password is incorrect.
        :status 200: You could find token from the response body:
                     ``{"status": "SUCCESS", "data": {"token": "..",
                     "expires_in": 1}}``
        
Obtains an user token by checking username and password.
Obtains an user token by checking username and password .
def post(self):
        username = request.form['username'].strip()
        password = request.form['password'].strip()
        expires_in = request.form.get('expiration', type=int, default=0)
        if expires_in > 0:
            expires_in = min(expires_in, settings.ADMIN_MAX_EXPIRATION)
        else:
            expires_in = settings.ADMIN_MAX_EXPIRATION
        user = User.get_by_name(username)
        if user is None or user.is_application:
            raise UserNotExistedError('user not found')
        if not user.check_password(password):
            raise LoginError("username or password not correct")
        g.auth = SessionAuth.from_user(user)
        with audit_log(audit_log.types.OBTAIN_USER_TOKEN, user=user):
            token = user.generate_token(settings.SECRET_KEY, expires_in)
            return api_response({'token': token, 'expires_in': expires_in})
def post ( self ) : username = request . form [ 'username' ] . strip ( ) password = request . form [ 'password' ] . strip ( ) expires_in = request . form . get ( 'expiration' , type = int , default = 0 ) if expires_in > 0 : expires_in = min ( expires_in , settings . ADMIN_MAX_EXPIRATION ) else : expires_in = settings . ADMIN_MAX_EXPIRATION user = User . get_by_name ( username ) if user is None or user . is_application : raise UserNotExistedError ( 'user not found' ) if not user . check_password ( password ) : raise LoginError ( "username or password not correct" ) g . auth = SessionAuth . from_user ( user ) with audit_log ( audit_log . types . OBTAIN_USER_TOKEN , user = user ) : token = user . generate_token ( settings . SECRET_KEY , expires_in ) return api_response ( { 'token' : token , 'expires_in' : expires_in } )
Obtains an user token by checking username and password.
Obtains an user token by checking username and password .
"""Obtains an user token by checking username and password.

        :form username: Required. The username of user.
        :form password: Required. The password of user.
        :form expiration: Optional. The life time in seconds of the token.
                          ``0`` or omitted will make token be expired in 30
                          days. Default is ``0``.
        :<header Content-Type: :mimetype:`application/x-www-form-urlencoded`
        :status 400: The username or password is incorrect.
        :status 200: You could find token from the response body:
                     ``{"status": "SUCCESS", "data": {"token": "..",
                     "expires_in": 1}}``
        """
self
form
Required. The username of user.
Required . The username of user .
form
Required. The password of user.
Required . The password of user .
form
Optional. The life time in seconds of the token.
``0`` or omitted will make token be expired in 30
days.
Optional . The life time in seconds of the token . ` ` 0 ` ` or omitted will make token be expired in 30 days .
<header
None
status
The username or password is incorrect.
The username or password is incorrect .
status
You could find token from the response body:
``{"status": "SUCCESS", "data": {"token": "..",
"expires_in": 1}}``
You could find token from the response body : ` ` { " status " : " SUCCESS " " data " : { " token " : " .. " " expires_in " : 1 }} ` `