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
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()
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
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
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
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
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))
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
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
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
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
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
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))
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'])
def get_by_email(useremail): try: return TabMember.get(user_email=useremail) except: return None
def query_all(limit=50): ''' Return some of the records. Not all. ''' return TabMember.select().limit(limit)
def get_by_name(uname): try: return TabMember.get(user_name=uname) except: return None
def set_sendemail_time(uid): entry = TabMember.update( time_email=tools.timestamp(), ).where(TabMember.uid == uid) entry.execute()
def get_by_keyword(par2): return TabMember.select().where(TabMember.user_name.contains(par2))
def get_by_uid(uid): try: return TabMember.get(TabMember.uid == uid) except: return None
def count_of_certain(): ''' ''' # adding ``None`` to hide ``No value for argument 'database' in method call`` return TabMember.select().count(None)
def update_time_login(u_name): entry = TabMember.update(time_login=tools.timestamp()).where( TabMember.user_name == u_name) entry.execute()
def total_number(): ''' Return the number of certian slug. ''' return TabMember.select().count()
def query_pager_by_slug(current_page_num=1): ''' Query pager ''' return TabMember.select().paginate(current_page_num, CMS_CFG['list_num'])
def get_by_Email(par2): ''' Get Member by keyword ''' return TabMember.select().where(TabMember.user_email.contains(par2))
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)
def count_of_certain(): recs = TabMember.select() return recs.count()