def __add_user_to_db(post, active, host): user = User() user.username = post['email_username'] user.email = post['email_username'] user.set_password(post['password']) user.first_name = post['realname'] user.is_active = active user.save() #为user创建mail统计记录 mail_statistic = MailStatistic() mail_statistic.user = user mail_statistic.save() profile = Profile() profile.user = user if active == 0: from Captcha.Base import randomIdentifier profile.activate_code = randomIdentifier()[:20] profile.save() if active == 0: url = profile.activate_code + str(profile.id) mail_content = ''' 请通过访问此链接http://%s/login/activate/%s/ 激活您的ClubHome账户。 ''' % (host, url) try: user.email_user('ClubHome账户激活', mail_content) except Exception, e: profile.delete() mail_statistic.delete() user.delete() return False
def reset_random_password(user): import types if isinstance(user, (types.UnicodeType, types.StringType)): user = User.objects.get(id=user) #为用户生成新的随机密码 from Captcha.Base import randomIdentifier new_password = randomIdentifier()[:10] #将随机密码发送到用户邮箱 try: user.email_user('您的新密码', new_password) user.is_staff = True #标志位,表示密码已被重置 except Exception, e: return False
def new(self): """Create a new instance of our assigned BaseCaptcha subclass, passing it any extra arguments we're given. This stores the result for later testing. """ self.clean() image = ImageGenerator() imageId = '' while True: imageId = randomIdentifier() if imageId in self.storedImages: continue else: break image.id = imageId relative_path = '/validate_img/%s.png' % imageId try: os.makedirs(settings.VALIDATE_IMAGE_ROOT + '/validate_img') except: pass image.storePath = settings.VALIDATE_IMAGE_ROOT + relative_path self.storedImages[image.id] = image image.render().save(image.storePath) return image.solutions[0], relative_path
def make_solution(): return randomIdentifier(alphabet=string.ascii_letters, length=SOL_LENGTH).upper()
def get_iden(): return randomIdentifier(length=IDEN_LENGTH)
def make_solution(): return randomIdentifier(alphabet=string.ascii_letters, length = SOL_LENGTH).upper()
def make_solution(): return randomIdentifier(alphabet=string.ascii_letters, length = g.captcha_sol_length).upper()