Example #1
0
 def delete_by_user_name(user_name):
     '''
     Delete user in the database by `user_name`.
     '''
     try:
         del_count = TabMember.delete().where(TabMember.user_name == user_name)
         del_count.execute()
         return True
     except:
         return False
Example #2
0
 def update_time_login(u_name):
     '''
     Update the login time for user.
     '''
     entry = TabMember.update(
         time_login=tools.timestamp()
     ).where(
         TabMember.user_name == u_name
     )
     entry.execute()
Example #3
0
 def delete(user_id):
     '''
     Delele the  user in the database by `user_id`.
     '''
     try:
         del_count = TabMember.delete().where(TabMember.uid == user_id)
         del_count.execute()
         return True
     except:
         return False
Example #4
0
 def update_time_reset_passwd(user_name, the_time):
     '''
     Update the time when user reset passwd.
     '''
     entry = TabMember.update(time_reset_passwd=the_time, ).where(
         TabMember.user_name == user_name)
     try:
         entry.execute()
         return True
     except:
         return False
Example #5
0
 def update_role(u_name, newprivilege):
     '''
     Update the role of the usr.
     '''
     entry = TabMember.update(role=newprivilege).where(
         TabMember.user_name == u_name)
     try:
         entry.execute()
         return True
     except:
         return False
Example #6
0
    def update_pass(user_id, newpass):

        out_dic = {'success': False, 'code': '00'}

        entry = TabMember.update(user_pass=tools.md5(newpass)).where(
            TabMember.uid == user_id)
        entry.execute()

        out_dic['success'] = True

        return out_dic
Example #7
0
 def query_nologin():
     '''
     Query the users who do not login recently (90 days).
     and not send email (120 days).
     time_model: num * month * hours * minite * second
     time_login: 3 * 30 * 24 * 60 * 60
     time_email: 4 * 30 * 24 * 60 * 60
     '''
     time_now = tools.timestamp()
     return TabMember.select().where((
         (time_now - TabMember.time_login) > 7776000) & (
             (time_now - TabMember.time_email) > 10368000))
Example #8
0
 def delete(user_id):
     '''
     Delele the  user in the database by `user_id`.
     :param user_id: ID of the user.
     :return: True if success else False.
     '''
     try:
         del_count = TabMember.delete().where(TabMember.uid == user_id)
         del_count.execute()
         return True
     except:
         return False
Example #9
0
    def check_user_by_name(user_name, u_pass):
        '''
        Checking the password by user's name.
        '''
        the_query = TabMember.select().where(TabMember.user_name == user_name)
        if the_query.count() == 0:
            return -1

        the_user = the_query.get()
        if the_user.user_pass == tools.md5(u_pass):
            return 1
        return 0
Example #10
0
    def create_user(post_data):
        '''
        Create the user.
        The code used if `False`.
        11: standsfor invalid username.
        21: standsfor invalide E-mail.
        91: standsfor unkown reson.
        '''
        out_dic = {'success': False, 'code': '00'}

        if post_data['user_name'].startswith('_'):
            '''
            the user_name startwith with ``_``, ONLY used for inner, not for login.            
            '''
            pass
        elif not tools.check_username_valid(post_data['user_name']):
            out_dic['code'] = '11'
            return out_dic

        if not tools.check_email_valid(post_data['user_email']):
            out_dic['code'] = '21'
            return out_dic

        try:
            TabMember.create(
                uid=tools.get_uuid(),
                user_name=post_data['user_name'],
                user_pass=tools.md5(post_data['user_pass']),
                user_email=post_data['user_email'],
                role='1000',  # ‘1000' as default role.
                time_create=tools.timestamp(),
                time_update=tools.timestamp(),
                time_reset_passwd=tools.timestamp(),
                time_login=tools.timestamp(),
                time_email=tools.timestamp())

            out_dic['success'] = True
        except:
            out_dic['code'] = '91'
        return out_dic
Example #11
0
    def update_user_name(user_email, user_name):
        '''
        Update the user_name of a user.
        '''

        out_dic = {'success': False, 'code': '00'}

        entry = TabMember.update(user_name=user_name).where(
            TabMember.user_email == user_email)
        entry.execute()

        out_dic['success'] = True

        return out_dic
Example #12
0
    def update_info(user_id, newemail):

        out_dic = {'success': False, 'code': '00'}
        if tools.check_email_valid(newemail):
            pass
        else:
            out_dic['code'] = '21'
            return out_dic

        entry = TabMember.update(user_email=newemail).where(
            TabMember.uid == user_id)
        entry.execute()

        out_dic['success'] = True

        return out_dic
Example #13
0
 def query_nologin():
     time_now = tools.timestamp()
     # num * month * hours * minite * second
     return TabMember.select().where((
         (time_now - TabMember.time_login) > 3 * 30 * 24 * 60 * 60) & (
             (time_now - TabMember.time_email) > 4 * 30 * 24 * 60 * 60))
Example #14
0
 def query_pager_by_time(current_page_num=1):
     '''
     Query pager
     '''
     return TabMember.select().where(TabMember.time_create).paginate(
         current_page_num, CMS_CFG['list_num'])
Example #15
0
 def get_by_email(useremail):
     try:
         return TabMember.get(user_email=useremail)
     except:
         return None
Example #16
0
 def query_all(limit=50):
     '''
     Return some of the records. Not all.
     '''
     return TabMember.select().limit(limit)
Example #17
0
 def get_by_name(uname):
     try:
         return TabMember.get(user_name=uname)
     except:
         return None
Example #18
0
 def set_sendemail_time(uid):
     entry = TabMember.update(
         time_email=tools.timestamp(), ).where(TabMember.uid == uid)
     entry.execute()
Example #19
0
 def get_by_keyword(par2):
     return TabMember.select().where(TabMember.user_name.contains(par2))
Example #20
0
 def get_by_uid(uid):
     try:
         return TabMember.get(TabMember.uid == uid)
     except:
         return None
Example #21
0
 def count_of_certain():
     '''
     '''
     # adding ``None`` to hide ``No value for argument 'database' in method call``
     return TabMember.select().count(None)
Example #22
0
 def update_time_login(u_name):
     entry = TabMember.update(time_login=tools.timestamp()).where(
         TabMember.user_name == u_name)
     entry.execute()
Example #23
0
 def total_number():
     '''
     Return the number of certian slug.
     '''
     return TabMember.select().count()
Example #24
0
 def query_pager_by_slug(current_page_num=1):
     '''
     Query pager
     '''
     return TabMember.select().paginate(current_page_num,
                                        CMS_CFG['list_num'])
Example #25
0
 def get_by_Email(par2):
     '''
     Get Member by keyword
     '''
     return TabMember.select().where(TabMember.user_email.contains(par2))
Example #26
0
 def total_number():
     '''
     Return the number of certian slug.
     '''
     # adding ``None`` to hide ``No value for argument 'database' in method call``
     return TabMember.select().count(None)
Example #27
0
    def count_of_certain():
        recs = TabMember.select()

        return recs.count()