def chpwdoneself(): userinfo = request.form.to_dict() data = db.change_pass(session['username'],userinfo['username'], userinfo['oldpasswd'], userinfo['newpasswd']) user_email = json.loads(db.get_one(['email'], 'name="%s"' % session['username'], 'users'))['email'] if data['code'] == 1: send_mail.delay([user_email], '个人密码修改失败', data['errmsg']) elif data['code'] == 0: send_mail.delay([user_email], '个人密码修改成功', data['errmsg']) util.WriteLog('infoLogger').info('%s changed his password' % (session['username'])) return json.dumps(data)
def updateoneself(): userinfo = request.form.to_dict() user_data = dict({'name_cn': userinfo['name_cn'], 'email':userinfo['email'], 'mobile': userinfo['mobile']}) data = db.user_update_oneself(userinfo['name'], user_data) if data['code'] == 0: send_mail.delay(userinfo['email'], '个人资料修改成功', '您的个人资料已修改') elif data['code'] == 1: send_mail.delay(userinfo['email'], '个人资料修改失败', '您的个人资料修改失败') util.WriteLog('infoLogger').info('%s changed his userinfo' % (session['username'])) return json.dumps(data)
def indexPage(request, template): """ Представление единственной страницы, содержащей форму """ if request.method == 'POST': category = request.POST.get('category', '') datepicker1 = request.POST.get('datepicker1', '') hours1 = request.POST.get('hours1', '') minutes1 = request.POST.get('minutes1', '') datepicker2 = request.POST.get('datepicker2', '') hours2 = request.POST.get('hours2', '') minutes2 = request.POST.get('minutes2', '') email = request.POST.get('email', '') if category and datepicker1 and datepicker2 and email: send_mail.delay(email, category, datepicker1, hours1, minutes1, datepicker2, hours2, minutes2) return HttpResponseRedirect(reverse('lenta')) return render_to_response(template, context_instance=RequestContext(request))
def email_captcha(): # form = EmailCaptchaForm(request.form) # print(form.email.data) # if form.validate(): # email = form.email.data email = request.args.get('email') if not email and email == None: return restful.params_error(message="邮箱不能为空!") if email == g.cms_user.email: return restful.params_error(message="新邮箱不能与原邮箱一样!") source = list(string.ascii_letters+string.digits) captcha = ''.join(random.sample(source, 6)) # message = Message('zcbbs邮箱验证码', recipients=[email], body="您的邮箱验证码为:%s" % captcha) # try: # mail.send(message) # except: # return restful.server_error() # return restful.success() send_mail.delay('bbs论坛邮箱验证码', [email], '您的邮箱验证码为:%s' % captcha) memcaches.set(email, captcha) return restful.success()
def email_captcha(): email = request.args.get('email') if not email: return restful.params_error('请输入邮箱参数!') soure = list(string.ascii_letters) soure.extend(map(lambda x: str(x), range(0, 10))) captcha = ''.join(random.sample(soure, 6)) # 给这个邮箱发送邮件 # message = Message( # '在线知识库邮箱验证', # recipients=[email], # body='您的验证码是:%s' % captcha # ) # try: # mail.send(message) # except: # return restful.server_error() send_mail.delay('在线知识库邮箱验证',[email],'您的验证码是:%s' % captcha) kfcache.set(email, captcha) return restful.success()
def email_captcha(): # /email_capthca/[email protected] email = request.args.get('email') if not email: return restful.params_error('请传递邮箱参数!') # source.extend(["0","1","2","3","4","5","6","7","8","9"]) source = list(string.ascii_letters) source.extend(map(lambda x: str(x), range(0, 10))) captcha = "".join(random.sample(source, 6)) # 给这个邮箱发送邮件 message = Message('Python论坛邮箱验证码', recipients=[email], body='您的验证码是:%s' % captcha) try: # mail.send(message) send_mail.delay(message) except: return restful.server_error() zlcache.set(email, captcha) return restful.success()
def email_captcha(): email = request.args.get('email') if not email: return restful.params_error('请输入邮箱') source = list(string.ascii_letters) # 获取26个字母列表 source.extend(map(lambda x:str(x), range(0,10))) # 生成0-9数字,并将其转成字符串,插入字母中 captcha = ''.join(random.sample(source, 6)) # 从列表中随机取出6个字符,并将其合并成完整的字符串 # 发送邮件内容 # message = Message('论坛验证码', recipients=[email], body='您的验证码是:%s'%captcha) # try: # mail.send(message) # except Exception as e: # return restful.server_error('内部异常') send_mail.delay('论坛验证码', [email], '您的验证码是:%s'%captcha) # 将验证码存在redis中 try: se = current_app.redis se.setex('email', 60 * 5, captcha) except RedisError as e: print(e) return 'redis问题' return restful.success()
def email_captcha(): # 获取要修改的邮箱 email = request.args.get('email') if not email: return restful.params_error('请输入要修改的邮箱') # 得到大小写字母的列表 source = list(string.ascii_letters) # 得到大小写字母的列表 + 0到9的数字字符串 source.extend(map(lambda x: str(x), range(0, 10))) # 随机取六位作为验证码 captcha = "".join(random.sample(source, 6)) # 给这个邮箱发送邮件验证码 # message = Message(subject='derek论坛密码修改邮件发送', recipients=[email,], body='你的验证码是:%s'%captcha) # try: # mail.send(message) # except: # return restful.server_error() # celery异步发送邮件 send_mail.delay('derek论坛密码修改邮件发送', [email], '你的验证码是:%s' % captcha) # 把邮箱和验证码保存到memcached中 zlcache.set(email, captcha) return restful.success()
def send_email(): email = request.args.get('email') if email: strnum = list(string.ascii_letters) num = map(lambda x:str(x),range(10)) strnum.extend(num) captche = "".join(random.sample(strnum,6)) try: send_mail.delay('Python论坛邮箱验证码', [email], '您的验证码是:%s' % captche) redis.set(email, captche, 120) return restful.success('邮件发送成功!') except Exception as e: return restful.server_error(str(e)) # message = Message('后台邮箱验证码',body='你的验证码是:'+captche,recipients=[email]) # try: # mail.send(message) # redis.set(email,captche,120) # return restful.success('邮件发送成功!') # except Exception as e: # return restful.server_error(str(e)) # pass else: return restful.params_error('请输入邮箱地址!')
def sms_captcha(): form = SMSCaptchaForm(request.form) if form.validate(): email = form.email.data captcha = Captcha.gene_num(number=4) #twilio client # client = Client(config.ACCOUNT_SID, config.AUTH_TOKEN) # # message = client.messages \ # .create( # body="Your DianMeng's verification code is:%s." %captcha, # from_='+14704129144', # to='+86' + telephone, # ) send_mail.delay('来自萌星的验证码', [email], '你的注册验证码为:%s' % captcha) print('发送邮件验证码为:', captcha) dmcache.set(email, captcha) return restful.success() else: return restful.params_error(message='请检查邮件格式')
def sendmail_captcha(): email = request.args.get('email') if not email: return restful.params_error('请传递邮箱参数!') captcha = list(string.ascii_letters) # 获得a-zA-Z的字符串 列表 captcha_num = map(lambda x: str(x), range(0, 10)) # 获得0-9的数字 的列表 captcha.extend(captcha_num) # 列表的一个方法,使得列表之间能够继承 # print("".join(captcha)) # 结合完毕,剩下就是随机打印出6个不同的字符串和数字了 result_captcha = random.sample(captcha, 6) result_captcha = "".join(result_captcha) print(result_captcha) message = Message("bbs论坛验证码", recipients=[email], body="关于您更改默认邮箱,我们向您发送了一条邮箱验证码,邮箱验证码为%s ,如果不是本人操作,请自觉忽略" % result_captcha) try: send_mail.delay('知了论坛邮箱验证码', recipients=[email], body='你的验证码是:%s' % captcha) except: return restful.server_error() zlcache.set(email, captcha) # 添加验证码缓存 return restful.success()
def test_mail(): from tasks import send_mail send_mail.delay(subject='celery测试', recipients=['*****@*****.**'], body='celery body') return 'success'
# -*- coding: utf-8 -*- from tasks import send_mail if __name__ == '__main__': send_mail.delay()
from tasks import send_mail if __name__ == '__main__': send_mail.delay('*****@*****.**')
def post(self, request): msg = '确认入职成功' success = True log = APIUserLog() try: raw_data = request.data log.logger.info(raw_data) username = raw_data.get('username', None) first_name = raw_data.get('first_name', None) """检查必要参数""" if not (username or first_name): raise Exception('用户名或者用户拼音至少需要一个') if username: org = OrganizationMptt.objects.filter(name=username) else: org = OrganizationMptt.objects.filter( user__first_name=first_name) if org: org.update(**{'is_register': 1, 'is_active': 1}) user = org[0].user user.is_active = 1 user.save(update_fields=['is_active']) """记录操作日志""" UserChangeRecord.objects.create(create_user=request.user, change_obj=org[0].name, type=5) """查找临时表,判断是否需要开通外部帐号""" outer_account = OuterAccountTemp.objects.filter(org=org) if outer_account: outer_account = outer_account[0] is_email = outer_account.is_email is_qq = outer_account.is_qq is_wifi = outer_account.is_ldap org = org[0] organization_char = org.get_ancestors_except_self_by_slash( ) # 添加企业邮箱 if int(is_email) == 1: log.logger.info( '{} 开通企业邮箱forcegames帐号'.format(first_name)) add_email_account( org.user.first_name + '@forcegames.cn', org.name, org.sex, organization_char, org.title, org.id) if int(is_email) == 2: log.logger.info( '{} 开通企业邮箱chuangyunet帐号'.format(first_name)) add_email_account( org.user.first_name + '@chuangyunet.com', org.name, org.sex, organization_char, org.title, org.id) if int(is_email) == 3: log.logger.info( '{} 开通企业邮箱forcegames和chuangyunet帐号'.format( first_name)) add_email_account( org.user.first_name + '@forcegames.cn', org.name, org.sex, organization_char, org.title, org.id) add_email_account( org.user.first_name + '@chuangyunet.com', org.name, org.sex, organization_char, org.title, org.id) # 添加企业QQ帐号 if int(is_qq) == 1: log.logger.info('{} 开通企业QQ帐号'.format(first_name)) add_qq_user(org.user.first_name, org.name, org.sex, organization_char, org.title, org.id) # 添加wifi if int(is_wifi) == 1: log.logger.info('{} 开通ldap帐号'.format(first_name)) ldap = LDAP() password = gen_password(10) gid = int('20000000') uid = org.user.first_name ldap.add_people_ou(uid, gid, userPassword=password) ldap.add_group_ou(gid, uid) ldap.unbind() to_list = [org.user.email] subject = '入职CMDB和wifi账号信息' content = user_add_nofity(org.user.first_name, password) send_mail.delay(to_list, subject, content, 10) # 删除临时表记录 outer_account.delete() # 发送新入职员工信息给前台(企业微信) content = make_new_user_info_share_content(org.id) try: touser_list = SpecialUserParamConfig.objects.get( param='LL_RECEPTION').user.all() touser = '******'.join([x.first_name for x in touser_list]) except: touser = None if touser: send_weixin_message.delay(touser=touser, content=content) else: raise Exception('用户不存在') except Exception as e: msg = str(e) success = False finally: if success: log.logger.info(msg) else: log.logger.error(msg) return JsonResponse({'success': success, 'msg': msg})