Example #1
0
    def post(self):
        action = self.get_argument("action")
        message = None

        if action != "add_user":
            raise HTTPError(400, "Unknown action")

        add_user_form = AddUserForm(self.request.arguments)

        if add_user_form.validate():
            username = add_user_form.username.data
            password = add_user_form.password.data

            try:
                User.save_new_user(username, password)
            except IntegrityError:
                message = "User already exists."
            else:
                logger.info("Added new user %s", username)
                self.redirect(self.reverse_url("user.overview", username))
                return

        self.render(
            "admin/account/all.html", add_user_form=add_user_form, usernames=User.all_usernames(), message=message
        )
Example #2
0
    def post(self):
        action = self.get_argument('action')
        message = None

        if action != 'add_user':
            raise HTTPError(400, 'Unknown action')

        add_user_form = AddUserForm(self.request.arguments)

        if add_user_form.validate():
            username = add_user_form.username.data
            password = add_user_form.password.data

            try:
                User.save_new_user(username, password)
            except IntegrityError:
                message = 'User already exists.'
            else:
                logger.info(self.user_audit_text('Added new user %s'),
                            username)
                self.redirect(self.reverse_url('user.overview', username))
                return

        self.render(
            'admin/account/all.html',
            add_user_form=add_user_form,
            usernames=User.all_usernames(),
            message=message
        )
Example #3
0
 def _delete(self, username, form):
     if form.validate():
         logger.info("Deleted user %s", username)
         User.delete_user(username)
         self.redirect(self.reverse_url("users.overview"))
     else:
         return "Error"
Example #4
0
 def _delete(self, username, form):
     if form.validate():
         logger.info(self.user_audit_text('Deleted user %s'), username)
         User.delete_user(username)
         self.redirect(self.reverse_url('users.overview'))
     else:
         return 'Error'
Example #5
0
    def _login(self, username, password):
        if User.no_users_exist():
            User.save_new_user(username, password)

        if User.check_account(username, password):
            self.set_secure_cookie(ACCOUNT_COOKIE_NAME, username, expires_days=30)
            self.set_secure_cookie(ACCOUNT_TOKEN_COOKIE_NAME, User.get_user_token(username), expires_days=30)
            return True
Example #6
0
    def _password(self, username, form):
        if form.validate():
            if form.username.data != username:
                return "Wrong username"

            logger.info("Updated user %s password", username)
            User.update_password(username, form.password.data)
            self.redirect(self.reverse_url("users.overview"))
        else:
            return "Error"
Example #7
0
    def _password(self, username, form):
        if form.validate():
            if form.username.data != username:
                return 'Wrong username'

            logger.info(self.user_audit_text('Updated user %s password'),
                        username)
            User.update_password(username, form.password.data)
            self.redirect(self.reverse_url('users.overview'))
        else:
            return 'Error'
Example #8
0
    def get(self):
        add_user_form = AddUserForm()

        self.render(
            'admin/account/all.html',
            usernames=User.all_usernames(),
            add_user_form=add_user_form
        )
Example #9
0
    def get_current_user(self):
        username_raw = self.get_secure_cookie(ACCOUNT_COOKIE_NAME)
        token = self.get_secure_cookie(ACCOUNT_TOKEN_COOKIE_NAME)

        if username_raw and token:
            username = username_raw.decode('ascii')

            if username and User.check_account_session(username, token):
                return username
Example #10
0
    def get_current_user(self):
        username_raw = self.get_secure_cookie(ACCOUNT_COOKIE_NAME)

        if username_raw:
            username = username_raw.decode('ascii')

            if username:
                if User.is_user_exists(username):
                    return username