Esempio n. 1
0
 def CheckAdminAccount(self):
     #判断管理员账号是否存在
     #如果管理员账号不存在,创建一个,并返回False,否则返回True
     u = KeUser.all().filter("name = ", 'admin').get()
     if not u:
         myfeeds = Book(title=MY_FEEDS_TITLE,
                        description=MY_FEEDS_DESC,
                        builtin=False,
                        keep_image=True,
                        oldest_article=7,
                        needs_subscription=False,
                        separate=False)
         myfeeds.put()
         secret_key = new_secret_key()
         au = KeUser(name='admin',
                     passwd=hashlib.md5('admin' + secret_key).hexdigest(),
                     kindle_email='',
                     enable_send=False,
                     send_time=8,
                     timezone=TIMEZONE,
                     book_type="mobi",
                     device='kindle',
                     expires=None,
                     ownfeeds=myfeeds,
                     merge_books=False,
                     secret_key=secret_key,
                     expiration_days=0)
         au.put()
         return False
     else:
         return True
Esempio n. 2
0
    def POST(self):
        u, up1, up2 = web.input().get('u'), web.input().get('up1'), web.input().get('up2')
        expiration = str_to_int(web.input().get('expiration', '0'))
        op, p1, p2 = web.input().get('op'), web.input().get('p1'), web.input().get('p2')
        user = self.getcurrentuser()
        users = KeUser.all() if user.name == 'admin' else None
        
        if all((op, p1, p2)): #修改当前登陆账号的密码
            secret_key = user.secret_key or ''
            try:
                pwd = hashlib.md5(op+secret_key).hexdigest()
                newpwd = hashlib.md5(p1+secret_key).hexdigest()
            except:
                tips = _("The password includes non-ascii chars!")
            else:
                if user.passwd != pwd:
                    tips = _("Old password is wrong!")
                elif p1 != p2:
                    tips = _("The two new passwords are dismatch!")
                else:
                    tips = _("Change password success!")
                    user.passwd = newpwd
                    user.put()
            return self.render('admin.html', "Admin", current='admin', user=user, users=users, chpwdtips=tips)
        elif all((u, up1, up2)): #添加账户
            if user.name != 'admin':
                raise web.seeother(r'/')
            elif not u:
                tips = _("Username is empty!")
            elif up1 != up2:
                tips = _("The two new passwords are dismatch!")
            elif KeUser.all().filter("name = ", u).get():
                tips = _("Already exist the username!")
            else:
                secret_key = new_secret_key()
                try:
                    pwd = hashlib.md5(up1 + secret_key).hexdigest()
                except:
                    tips = _("The password includes non-ascii chars!")
                else:
                    myfeeds = Book(title=MY_FEEDS_TITLE, description=MY_FEEDS_DESC,
                        builtin=False, keep_image=True, oldest_article=7, 
                        needs_subscription=False, separate=False)
                    myfeeds.put()
                    au = KeUser(name=u, passwd=pwd, kindle_email='', enable_send=False,
                        send_time=7, timezone=TIMEZONE, book_type="mobi",
                        ownfeeds=myfeeds, merge_books=False, secret_key=secret_key, expiration_days=expiration)
                    if expiration:
                        au.expires = datetime.datetime.utcnow() + datetime.timedelta(days=expiration)

                    au.put()
                    users = KeUser.all() if user.name == 'admin' else None
                    tips = _("Add a account success!")
            return self.render('admin.html', "Admin", current='admin', user=user, users=users, actips=tips)
        else:
            return self.GET()
Esempio n. 3
0
 def POST(self):
     u,up1,up2 = web.input().get('u'),web.input().get('up1'),web.input().get('up2')
     op,p1,p2 = web.input().get('op'), web.input().get('p1'), web.input().get('p2')
     user = self.getcurrentuser()
     users = KeUser.all() if user.name == 'admin' else None
     if all((op, p1, p2)): #修改当前登陆账号的密码
         secret_key = user.secret_key or ''
         try:
             pwd = hashlib.md5(op+secret_key).hexdigest()
             newpwd = hashlib.md5(p1+secret_key).hexdigest()
         except:
             tips = _("The password includes non-ascii chars!")
         else:
             if user.passwd != pwd:
                 tips = _("Old password is wrong!")
             elif p1 != p2:
                 tips = _("The two new passwords are dismatch!")
             else:
                 tips = _("Change password success!")
                 user.passwd = newpwd
                 user.put()
         return self.render('admin.html',"Admin",
             current='admin', user=user, users=users,chpwdtips=tips)
     elif all((u, up1, up2)): #添加账户
         if user.name != 'admin':
             raise web.seeother(r'/')
         elif not u:
             tips = _("Username is empty!")
         elif up1 != up2:
             tips = _("The two new passwords are dismatch!")
         elif KeUser.all().filter("name = ", u).get():
             tips = _("Already exist the username!")
         else:
             secret_key = new_secret_key()
             try:
                 pwd = hashlib.md5(up1 + secret_key).hexdigest()
             except:
                 tips = _("The password includes non-ascii chars!")
             else:
                 myfeeds = Book(title=MY_FEEDS_TITLE, description=MY_FEEDS_DESC,
                     builtin=False, keep_image=True, oldest_article=7, 
                     needs_subscription=False, separate=False)
                 myfeeds.put()
                 au = KeUser(name=u, passwd=pwd, kindle_email='', enable_send=False,
                     send_time=7, timezone=TIMEZONE, book_type="mobi",
                     ownfeeds=myfeeds, merge_books=False, secret_key=secret_key)
                 au.expires = datetime.datetime.utcnow()+datetime.timedelta(days=180)
                 au.put()
                 users = KeUser.all() if user.name == 'admin' else None
                 tips = _("Add a account success!")
         return self.render('admin.html',"Admin",
             current='admin', user=user, users=users,actips=tips)
     else:
         return self.GET()
Esempio n. 4
0
 def CheckAdminAccount(self):
     #判断管理员账号是否存在
     #如果管理员账号不存在,创建一个,并返回False,否则返回True
     u = KeUser.all().filter("name = ", 'admin').get()
     if not u:            
         myfeeds = Book(title=MY_FEEDS_TITLE,description=MY_FEEDS_DESC,
                 builtin=False,keep_image=True,oldest_article=7,needs_subscription=False)
         myfeeds.put()
         secret_key = new_secret_key()
         au = KeUser(name='admin',passwd=hashlib.md5('admin'+secret_key).hexdigest(),
             kindle_email='',enable_send=False,send_time=8,timezone=TIMEZONE,
             book_type="mobi",device='kindle',expires=None,ownfeeds=myfeeds,merge_books=False,secret_key=secret_key)
         au.put()
         return False
     else:
         return True