Пример #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
        )
Пример #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
        )
Пример #3
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
Пример #4
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