Exemplo n.º 1
0
    def get(self, id):
        if self.group != '1':
            self.render("404.html", username=self.username, group=self.group)

        user_info = get_user_info_by_id(self.session, id)

        form = UserEditForm()
        form.status.choices = [(k, v) for k, v in self.status_name.iteritems()]
        form.status.choices.sort()
        form.group.choices = [(k, v) for k, v in self.group_name.iteritems()]
        form.group.choices.sort()

        if user_info is None:
             self.render("404.html", username=self.username, group=self.group)

        self.render(
                "admin/user_edit.html", 
                username=self.username,
                group=self.group, 
                status_name=self.status_name,
                group_name=self.group_name, 
                form=form, 
                db_error=None,
                user_info=user_info
        )
Exemplo n.º 2
0
    def get(self, dirname, pagename):
        level_info = get_level_info_by_uri(self.session, dirname, pagename)

        if level_info is None:
            self.render('404.html', username=self.username, group=self.group)

        user_info = get_user_info_by_id(self.session, self.uid)
        
        update_flag = update_progress(self.session, user_info.id,
                level_info.id, level_info.level, level_info.step)
        if update_flag != 0:
            self.render('404.html', username=self.username, group=self.group)
        
        # Special handler for media files
        audioname = '/media/' + level_info.audioname \
                if level_info.audioname else ''
        imgname = '/media/' + level_info.dirname + '/' + \
                level_info.imgname if level_info.imgname else ''
        imgalt = level_info.imgalt if level_info.imgalt else ''
        

        if level_info.type == 1:
            self.render(
                    'cipher_common.html',
                    username = self.username,
                    group = self.group,
                    title = level_info.title,
                    imgname = imgname,
                    imgalt = imgalt,
                    audioname = audioname,
                    hint = level_info.hint,
                    hiddencode = level_info.hiddencode,
                    redirectto = level_info.redirectto,
                    redirecttime = level_info.redirecttime,
            )
        elif level_info.type == 2:
            self.render(
                    'cipher_puretext.html',
                    username = self.username,
                    group = self.group,
                    title = level_info.title,
                    hiddencode = level_info.hiddencode,
                    puretexth1 = level_info.puretexth1,
                    puretextp = level_info.puretextp,
            )
        elif level_info.type == 3:
            self.render(
                    'cipher_redirect.html',
                    username = self.username,
                    group = self.group,
                    title = level_info.title,
                    redirectto = level_info.redirectto,
                    redirecttime = level_info.redirecttime,
            )
        else:
            self.render('404.html', username=self.username, group=self.group)
Exemplo n.º 3
0
    def get(self, dirname, pagename):
        level_info = get_level_info_by_uri(self.session, dirname, pagename)

        if level_info is None:
            self.render('404.html', username=self.username, group=self.group)

        user_info = get_user_info_by_id(self.session, self.uid)

        update_flag = update_progress(self.session, user_info.id,
                                      level_info.id, level_info.level,
                                      level_info.step)
        if update_flag != 0:
            self.render('404.html', username=self.username, group=self.group)

        # Special handler for media files
        audioname = '/media/' + level_info.audioname \
                if level_info.audioname else ''
        imgname = '/media/' + level_info.dirname + '/' + \
                level_info.imgname if level_info.imgname else ''
        imgalt = level_info.imgalt if level_info.imgalt else ''

        if level_info.type == 1:
            self.render(
                'cipher_common.html',
                username=self.username,
                group=self.group,
                title=level_info.title,
                imgname=imgname,
                imgalt=imgalt,
                audioname=audioname,
                hint=level_info.hint,
                hiddencode=level_info.hiddencode,
                redirectto=level_info.redirectto,
                redirecttime=level_info.redirecttime,
            )
        elif level_info.type == 2:
            self.render(
                'cipher_puretext.html',
                username=self.username,
                group=self.group,
                title=level_info.title,
                hiddencode=level_info.hiddencode,
                puretexth1=level_info.puretexth1,
                puretextp=level_info.puretextp,
            )
        elif level_info.type == 3:
            self.render(
                'cipher_redirect.html',
                username=self.username,
                group=self.group,
                title=level_info.title,
                redirectto=level_info.redirectto,
                redirecttime=level_info.redirecttime,
            )
        else:
            self.render('404.html', username=self.username, group=self.group)
Exemplo n.º 4
0
def delete_user(session, uid):
    user_info = get_user_info_by_id(session, uid)
    if user_info is None:
        return '1'

    if user_info.group == 1:
        return '2'

    try:
        session.delete(user_info)
        session.commit()
        return '0'
    except:
        return '1'
Exemplo n.º 5
0
    def post(self, id):
        if self.group != '1':
            self.render("404.html", username=self.username, group=self.group)

        arguments = {
                'username': self.get_argument("username"),
                'email': self.get_argument("email"),
                'password': self.get_argument("password"),
                'status': self.get_argument("status"),
                'group': self.get_argument("group"),
        }

        form = UserEditForm(self.request.arguments)
        form.status.choices = [(k, v) for k, v in self.status_name.iteritems()]
        form.status.choices.sort()
        form.group.choices = [(k, v) for k, v in self.group_name.iteritems()]
        form.group.choices.sort()
        
        user_info = get_user_info_by_id(self.session, id)
        if user_info is None:
             self.render("404.html", username=self.username, group=self.group)
        update_error = user_update_validation(self.session, 
                user_info, self.uid, arguments)
        
        if form.validate():
            if update_error == "":
                update_user_info(self.session, user_info, arguments)
                self.redirect("/admin/user/show/" + id)
            else:
                self.render(
                        "admin/user_edit.html", 
                        username=self.username,
                        group=self.group, 
                        status_name=self.status_name,
                        group_name=self.group_name, 
                        form=form,
                        db_error=update_error, 
                        user_info=user_info
                )
        else:
            self.render(
                    "admin/user_edit.html", 
                    username=self.username,
                    group=self.group, 
                    status_name=self.status_name,
                    group_name=self.group_name, 
                    form=form, 
                    db_error=None,
                    user_info=user_info
            )
Exemplo n.º 6
0
    def get(self, id):
        if self.group != '1':
            self.render("404.html", username=self.username, group=self.group)

        user_info = get_user_info_by_id(self.session, id)

        if user_info == None:
            self.render("404.html", username=self.username, group=self.group)

        self.render("admin/user_detail.html",
                    username=self.username,
                    group=self.group,
                    status_name=self.status_name,
                    group_name=self.group_name,
                    user_info=user_info)
Exemplo n.º 7
0
    def post(self, id):
        if self.group != '1':
            self.render("404.html", username=self.username, group=self.group)

        arguments = {
            'username': self.get_argument("username"),
            'email': self.get_argument("email"),
            'password': self.get_argument("password"),
            'status': self.get_argument("status"),
            'group': self.get_argument("group"),
        }

        form = UserEditForm(self.request.arguments)
        form.status.choices = [(k, v) for k, v in self.status_name.iteritems()]
        form.status.choices.sort()
        form.group.choices = [(k, v) for k, v in self.group_name.iteritems()]
        form.group.choices.sort()

        user_info = get_user_info_by_id(self.session, id)
        if user_info is None:
            self.render("404.html", username=self.username, group=self.group)
        update_error = user_update_validation(self.session, user_info,
                                              self.uid, arguments)

        if form.validate():
            if update_error == "":
                update_user_info(self.session, user_info, arguments)
                self.redirect("/admin/user/show/" + id)
            else:
                self.render("admin/user_edit.html",
                            username=self.username,
                            group=self.group,
                            status_name=self.status_name,
                            group_name=self.group_name,
                            form=form,
                            db_error=update_error,
                            user_info=user_info)
        else:
            self.render("admin/user_edit.html",
                        username=self.username,
                        group=self.group,
                        status_name=self.status_name,
                        group_name=self.group_name,
                        form=form,
                        db_error=None,
                        user_info=user_info)
Exemplo n.º 8
0
    def get(self, id):
        if self.group != '1':
            self.render("404.html", username=self.username, group=self.group)

        user_info = get_user_info_by_id(self.session, id)

        if user_info == None:
            self.render("404.html", username=self.username, group=self.group)

        self.render(
                "admin/user_detail.html", 
                username=self.username,
                group=self.group, 
                status_name=self.status_name,
                group_name=self.group_name,
                user_info=user_info
        )
Exemplo n.º 9
0
    def get(self, id):
        if self.group != '1':
            self.render("404.html", username=self.username, group=self.group)

        user_info = get_user_info_by_id(self.session, id)

        form = UserEditForm()
        form.status.choices = [(k, v) for k, v in self.status_name.iteritems()]
        form.status.choices.sort()
        form.group.choices = [(k, v) for k, v in self.group_name.iteritems()]
        form.group.choices.sort()

        if user_info is None:
            self.render("404.html", username=self.username, group=self.group)

        self.render("admin/user_edit.html",
                    username=self.username,
                    group=self.group,
                    status_name=self.status_name,
                    group_name=self.group_name,
                    form=form,
                    db_error=None,
                    user_info=user_info)