'Login with username and password'

@api.validate(login_api_schema, description=u'Username    and    Password')
@api.response(Unauthorized)
@api.response(200, u'Login    successful', model=base_message_schema)
@api.doc(parser=login_parser)
def post(self, session=None):

    data = request.json
    user_name = data.get(u'username')
    password = data.get(u'password')
    if data:
        user = session.query(User).filter((User.name == user_name.lower())).first()
        if user:
            if ((user_name == u'flexget') and (not user.password)):
                raise Unauthorized(u'If    this    is    your    first    time    running    the    WebUI    you    need    to    set    a    password    via    the    command    line    by    running    `flexget    web    passwd    <new_password>`')
            if (user.password and check_password_hash(user.password, password)):
                args = login_parser.parse_args()
                login_user(user, remember=args[u'remember'])
                return success_response(u'user    logged    in')
    raise Unauthorized(u'Invalid    username    or    password')
