コード例 #1
0
ファイル: admin.py プロジェクト: rrader/information-security
    def create_user_post_view(self):
        length = int(self.headers['Content-Length'])
        data = self.rfile.read(length)
        post_data = parse_qs(data.decode('utf-8'))

        name = post_data['name'][0]
        password = post_data['password'][0]
        logger.info("attempt to create user '{}'".format(name))
        if User.select().where(User.name == name).exists():
            logger.warn("user '{}' already exists!".format(name))
            self.render_template("message.html", message="Такой пользователь уже есть")
            return
        user = User.create(name=name, password=make_password(name, password))
        user.save()
        logger.info("user '{}' created successfully".format(name))
        self.send_response(302)
        self.send_header('location', '/admin')
        self.end_headers()
コード例 #2
0
    def can_read(self, user):
        if user.superuser:
            return True
        if user.name == self.owner:
            return self.ru
        return self.ro

    def can_write(self, user):
        if user.superuser:
            return True
        if user.name == self.owner:
            return self.wu
        return self.wo

    class Meta:
        database = DB

if __name__ == "__main__":
    from authentication import make_password
    if not FileResource.table_exists():
        FileResource.create_table()
    if not User.table_exists():
        User.create_table()

    try:
        User.select().where(User.name == 'admin').get()
    except DoesNotExist:
        admin = User.create(name='admin', superuser=True,
                            password=make_password('admin', 'admin'))
        admin.save()