Пример #1
0
    def POST(self):
        request_data = web.input()
        password=request_data['passwd']
        rpassword=request_data['rpasswd']
        if password != rpassword: 
            #如果passwd!=rpasswd
            error={'status':'failure','msg':"passwd is not equilt rpasswd"}
            return sher.main_render.register(error)

        user = User()
        row = user.getUserBy({'username':request_data['username'],'email':request_data['email']})
        if row:#如果用户名存在,提示更改用户名
            error={'status':'failure', 'msg':'user name existed'}
            return sher.main_render.register(error)

        createdata=int(time.time())#加入时间
        request_data['created']=createdata
        del request_data['rpasswd']#如果不存在当前用户,直接存储到数据库,回到login页面
        user.create_user(request_data)
        raise web.seeother('login',False)
Пример #2
0
    def POST(self):
        #得到用户输入表单中的username,password
        request_data = web.input()
        username = request_data['username']
        password = request_data['password']

        #得到model中user对象
        user = User()
        #从数据库中查出所有用户的帐号和密码,返回一个字典类型users
        row = user.getUserBy({'username':username, 'passwd':password}, fields = 'u_id')

        #判断用户输入是否存在并正确
        #若正确则为其创建session表示已登录
        if row:
            web.ctx.session.is_login = True
            result =  {'status':'success',}

            raise web.seeother('/', False)

        result =  {'status':'failure',}
        return sher.main_render.login(result)
Пример #3
0
class AdminUser():
    def __init__(self):
        self.user = User()
        pass

    def GET(self):
        request_data = web.input()
        if 'mod' in request_data:
            mod = request_data['mod']  
            if mod == 'list':
                return self.listUser(request_data)
            elif mod == 'view':
                return self.viewUser(request_data)

        return '404 page'

    def POST(self):
        request_data = web.input()
        if 'mod' in request_data:
            if mod == 'add':
                return self.addUser(request_data)
            elif mod == 'delete':
                return self.delUser(request_data)
            elif mod == 'update':
                return self.updateUser(request_data)

        return '404 page'

    def addUser(self):
        pass

    def updateUser(self):
        pass

    def delUser(self):
        """删除用户只是把用户重激活状态变成未激活状态"""
        pass

    def viewUser(self, request_data):
        u_id = None if 'u_id' not in request_data else int(request_data['u_id'])
        row = self.user.getUserBy({'u_id':u_id})
        
        return sher.admin_render.view_user(row)

    def listUser(self, request_data):
        """分页展示用户"""
        page_size = 2 
        pages = 3 
        current_page = 1 if 'page' not in request_data else int(request_data['page'])
        is_active = 1 if 'is_active' not in request_data else 0 
        condition = {'is_active':is_active}
        rows_count = self.user.getCount(condition)
        getRowsFunc = self.user.getUsers
        orderBy = 'u_id desc'
        fields = 'a.u_id, a.username, a.email, a.is_active, a.created, b.level_id, c.description'

        #引用分页
        data = page(page_size, pages, current_page, rows_count, getRowsFunc, condition, orderBy, fields)
        functions = {'tsp2date':utils.convTsp2Date,}
        data['functions'] = functions

        return sher.admin_render.list_user(data)