Example #1
0
    def post(self):
        if not self.is_authenticated():
            return
        username = self.get_argument('username')
        old_password = self.get_argument('old_password')
        new_password = self.get_argument('new_password')

        with transaction() as db:
            user = get_user_by_username_password(db, username, old_password)
            response = validate(user, get_settings(db), new_password, db)
            if response['success']:
                change_password(db, user, new_password, get_settings(db))
            self.res(response)
Example #2
0
def reset():
    if not self.is_authenticated():
        return
    username = self.get_argument('username')
    new_password = self.get_argument('new_password')
    token = self.get_argument('token')
    try:
        with transaction() as db:
            if is_admin(db, token):
                user = get_user_by_username(db, username)
                response = validate(user, get_settings(db), new_password, db)
                if response['success']:
                    change_password(db, user, new_password, get_settings(db))
                self.res(response)
            else:
                self.error(NOT_AUTHORIZED)
    except IntegrityError as e:
        self.error('Internal Error')
Example #3
0
def create():
    user: User = str_to_user(request.args.get('user'))
    token = request.args.get('token')
    try:
        with transaction() as db:
            if not verify_basic_auth(request) or not is_admin(db, token):
                return create_respond(error=UserAuthErrors.NOT_AUTHORIZED)
            msg = validate(user, get_settings(db), user.password, db)
            return create_respond(insert_user(db, user)) if msg == VALID else create_respond(error=msg)
    except IntegrityError:
        return create_respond(error='the username is already in used, choose other')
Example #4
0
 def post(self):
     if not self.is_authenticated():
         return
     token = self.get_argument('token')
     with transaction() as db:
         if is_admin(db, token):
             auth = get_settings(db)
             response = dict(auth.__dict__)
             response.pop('_sa_instance_state', None)
             response.pop('creation_datetime', None)
             response.pop('id', None)
             self.res(response)
         else:
             self.error(NOT_AUTHORIZED)
def fail_login(db: alchemy, user: User) -> int:
    settings = get_settings(db)
    user.failed_login_number += 1
    user.is_enabled = user.failed_login_number + 1 < settings.failed_login_maximum_number
    db.commit()
    return settings.failed_login_maximum_number - user.failed_login_number