def get(self, request): uf = qqForm(request.GET) if not uf.is_valid(): return JsonResponse({ "status": "error", "msg": "邮件发送失败" }) qq = uf.cleaned_data["qq"] user = User.objects.filter(qq__exact= qq).first() if user is None: msg = { "status" : 'error', "msg" : 'user not exist' } else: with open(BASE_DIR + "/api/mail_template/recover.html", 'rt', encoding='utf-8') as mail_template: template = mail_template.read() token = new_token(user, 'recover').get_token() link = "%s://%s/#/new_pwd/%s" %(protocol, domain, token) email_content = template % (user.qq, link, user_email, user_group) start_mail_thread( 'Qjob账户密码重置', email_content, ['*****@*****.**' % user.qq] ) msg = { "status" : 'success', "msg" : '邮件已发送,请注意查收' } return JsonResponse(msg)
def get(self, request): qq = request.GET['qq'] user = User.objects.filter(qq__exact = qq).first() if user is None: msg = { "status" : 'error', "msg" : 'user not exist' } else: if user.status == 1: msg = { "status" : 'error', "msg" : 'user already activated' } else: with open(BASE_DIR + "/api/mail_template/activate.html", 'rt') as mail_template: template = mail_template.read() token = new_token(user, 'activate').get_token() link = "http://www.qjob.social/api/activate/?token=" + token email_content = template % ('user', user.qq, link) start_mail_thread( 'Qjob account activate', email_content, email_address, ['*****@*****.**' % user.qq] ) msg = { "status" : 'success', "msg" : 'email is delivered' } return JsonResponse(msg)
def get(self, request): groupId = request.GET['id'] owner = GroupAdmin.objects.filter(groupId__exact= groupId, userType__exact = 1).first() if owner is None: msg = { "status" : 'error', "msg" : 'group not exist' } else: with open(BASE_DIR + "/api/mail_template/recover.html", 'rt') as mail_template: template = mail_template.read() token = new_token(owner, 'recover') token.id = groupId token = token.get_token() link = "http://www.qjob.social/api/group/recover/?token=" + token email_content = template % ('owner', owner.qq, link) start_mail_thread( 'Qjob account recover', email_content, email_address, ['*****@*****.**' % owner.qq] ) msg = { "status" : 'success', "msg" : 'email is delivered' } return JsonResponse(msg)
def get(self, request): token_str = request.GET['token'] token = parse_token(token_str, 'activate') if token is None: msg = {"status": "error", "msg": "error token"} else: if token.is_expired(): msg = {"status": "error", "msg": "token is expired"} else: admin = GroupAdmin.objects.filter(id__exact=token.id).first() if admin is None: msg = {"status": "error", "msg": "group not exsist"} else: if admin.status == 1: msg = { "status": "error", "msg": "The admin already activated" } else: if token.is_user(admin): admin.status = 1 admin.save() if admin.userType == 0: token = new_token(admin, 'recover') token.id = admin.id token = token.get_token() return HttpResponseRedirect( '/#/group/new_pwd/' + token) else: return HttpResponseRedirect('/#/group/login') else: msg = {"status": "error", "msg": "error token"} return JsonResponse(msg)
def post(self, request): check = CheckRequest(request) uf = LoginForm(check.jsonForm) if uf.is_valid(): qq = uf.cleaned_data['qq'] password = db_password(uf.cleaned_data['password']) # 获取的表单数据与数据库进行比较 user = User.objects.filter(qq__exact=qq, password__exact=password).first() if user: if user.status == 1: data = {"status": 'success', 'msg': "Login success"} user_token = new_token(user, 'login') token = user_token.get_token() cookieOpt = user_token.expired_time data['cookies'] = { 'token': { 'value': token, 'opt': cookieOpt } } response = JsonResponse(data) response.set_cookie("token", value=token, max_age=expiration['login'], httponly=True) response.set_cookie("logined", value="yes", max_age=expiration['login']) return response elif user.status == 0: return JsonResponse({ "status": 'success', "code": 30004, "msg": successCode[30004] }) else: return JsonResponse({ "status": 'error', 'msg': "用户状态不合法,请联系管理员" }) else: # 用户名或密码错误 return JsonResponse({ "status": 'error', 'msg': "email or password is error" }) else: return JsonResponse({ "status": 'error', 'msg': "login form is error" })
def post(self, request): check = CheckRequest(request); uf = LoginForm(check.jsonForm) if uf.is_valid(): groupId = uf.cleaned_data['groupId'] qq = uf.cleaned_data['qq'] password = db_password(uf.cleaned_data['password']) # 获取的表单数据与数据库进行比较 admin = GroupAdmin.objects.filter( groupId__exact=groupId, qq__exact=qq, password__exact=password ).first() if admin: if admin.userType == 1 and admin.status == 0: return JsonResponse({ "status": 'error', "msg": "群主帐号未激活" }) data = { "status": 'success', 'msg': "Login success" } admin_token = new_token(admin, 'login') token = admin_token.get_token() cookieOpt = admin_token.expired_time data['cookies'] = { 'token': { 'value': token, 'opt': cookieOpt } } response = JsonResponse(data) response.set_cookie("admin_token",value=token, max_age=expiration['login'], httponly=True) response.set_cookie("admin_logined",value="yes", max_age=expiration['login']) return response else: # 用户名或密码错误 return JsonResponse({"status": 'error', 'msg': "GroupID or qq or password is error" }) else: return JsonResponse({"status": 'error', 'msg': "login form is error: %s" % uf.errors })
def post(self, request): check = CheckRequest(request); uf = LoginForm(check.jsonForm) if uf.is_valid(): qq = uf.cleaned_data['qq'] password = db_password(uf.cleaned_data['password']) # 获取的表单数据与数据库进行比较 user = User.objects.filter(qq__exact=qq, password__exact=password).first() if user: if user.status == 1: data = {"status": 'success', 'msg': "Login success" } user_token = new_token(user, 'login') token = user_token.get_token() cookieOpt = user_token.expired_time data['cookies'] = { 'token': { 'value': token, 'opt': cookieOpt } } response = JsonResponse(data) response.set_cookie("token", value=token, max_age=expiration['login'], httponly=True) response.set_cookie("logined", value="yes", max_age=expiration['login']) return response elif user.status == 0: return JsonResponse({ "status" : 'success', "code": 30004, "msg": successCode[30004] }) else: return JsonResponse({ "status" : 'error', 'msg' : "用户状态不合法,请联系管理员" }) else: # 用户名或密码错误 return JsonResponse({"status": 'error', 'msg': "email or password is error" }) else: return JsonResponse({"status": 'error', 'msg': "login form is error" })
def get(self, request): uf = ActivaterForm(request.GET) if not uf.is_valid(): return JsonResponse({ "status": "error", "msg": "激活邮件发送失败,表单有误" }) groupId = uf.cleaned_data['groupId'] qq = uf.cleaned_data['qq'] admin = GroupAdmin.objects.filter(groupId__exact = groupId, qq__exact=qq).first() if admin is None: msg = { "status" : 'error', "msg" : 'Admin not exist' } else: if admin.status == 1: msg = { "status" : 'error', "msg" : 'group owner already activated' } else: group = Group.objects.filter(groupId__exact=groupId).first() if not group: return JsonResponse({ "status" : 'error', "msg" : '群ID不存在' }) with open(BASE_DIR + "/api/mail_template/admin_activate.html", 'rt', encoding='utf-8') as mail_template: template = mail_template.read() token = new_token(admin, 'activate') token = token.get_token() link = "%s://%s/api/group/activate/?token=%s" %(protocol, domain, token) email_content = template % (group.groupName, groupId, admin.qq, link, admin_email, admin_group) start_mail_thread( 'Qjob管理员账户激活', email_content, ['*****@*****.**' % admin.qq] ) msg = { "status" : 'success', "msg" : 'email is delivered' } return JsonResponse(msg)
def get(self, request): uf = ActivaterForm(request.GET) if not uf.is_valid(): return JsonResponse({ "status": "error", "msg": "激活邮件发送失败,表单有误" }) groupId = uf.cleaned_data['groupId'] qq = uf.cleaned_data['qq'] admin = GroupAdmin.objects.filter(groupId__exact = groupId, qq__exact=qq).first() if admin is None: msg = { "status" : 'error', "msg" : 'Admin not exist' } else: if admin.status == 1: msg = { "status" : 'error', "msg" : 'group owner already activated' } else: group = Group.objects.filter(groupId__exact=groupId).first() if not group: return JsonResponse({ "status" : 'error', "msg" : '群ID不存在' }) with open(BASE_DIR + "/api/mail_template/admin_activate.html", 'rt', encoding='utf-8') as mail_template: template = mail_template.read() token = new_token(admin, 'activate') token = token.get_token() link = "%s://%s/api/group/activate/?token=%s" %(protocol, domain, token) email_content = template % (group.groupName, admin.qq, link, admin_email, admin_group) start_mail_thread( 'Qjob管理员账户激活', email_content, ['*****@*****.**' % admin.qq] ) msg = { "status" : 'success', "msg" : 'email is delivered' } return JsonResponse(msg)
def get(self, request): token_str = request.GET['token'] token = parse_token(token_str, 'activate') if token is None: msg = { "status" : "error", "msg" : "error token" } else: if token.is_expired(): msg = { "status" : "error", "msg" : "token is expired" } else: admin = GroupAdmin.objects.filter(id__exact = token.id).first() if admin is None: msg = { "status" : "error", "msg" : "group not exsist" } else: if admin.status == 1: msg = { "status" : "error", "msg" : "The admin already activated" } else: if token.is_user(admin): admin.status = 1 admin.save() if admin.userType == 0: token = new_token(admin, 'recover') token.id = admin.id token = token.get_token() return HttpResponseRedirect('/#/group/new_pwd/'+token) else: return HttpResponseRedirect('/#/group/login') else: msg = { "status" : "error", "msg" : "error token" } return JsonResponse(msg)
def get(self, request): uf = RecoverForm(request.GET) if not uf.is_valid(): return JsonResponse({ "status": "error", "msg": "邮件发送失败" }) groupId = uf.cleaned_data["groupId"] qq = uf.cleaned_data["qq"] admin = GroupAdmin.objects.filter(groupId__exact=groupId, qq__exact=qq).first() if admin is None: msg = { "status" : 'error', "msg" : '群ID或管理员QQ不存在' } else: group = Group.objects.filter(groupId__exact=groupId).first() if not group: return JsonResponse({ "status" : 'error', "msg" : '群ID不存在' }) with open(BASE_DIR + "/api/mail_template/admin_recover.html", 'rt', encoding='utf-8') as mail_template: template = mail_template.read() token = new_token(admin, 'recover') token = token.get_token() link = "%s://%s/#/group/new_pwd/%s" %(protocol, domain, token) email_content = template % (group.groupName, groupId, admin.qq, link, admin_email, admin_group) start_mail_thread( 'Qjob管理员账户密码重置', email_content, ['*****@*****.**' % admin.qq] ) msg = { "status" : 'success', "msg" : 'email is delivered' } return JsonResponse(msg)
def get(self, request): uf = RecoverForm(request.GET) if not uf.is_valid(): return JsonResponse({ "status": "error", "msg": "邮件发送失败" }) groupId = uf.cleaned_data["groupId"] qq = uf.cleaned_data["qq"] admin = GroupAdmin.objects.filter(groupId__exact=groupId, qq__exact=qq).first() if admin is None: msg = { "status" : 'error', "msg" : '群ID或管理员QQ不存在' } else: group = Group.objects.filter(groupId__exact=groupId).first() if not group: return JsonResponse({ "status" : 'error', "msg" : '群ID不存在' }) with open(BASE_DIR + "/api/mail_template/admin_recover.html", 'rt', encoding='utf-8') as mail_template: template = mail_template.read() token = new_token(admin, 'recover') token = token.get_token() link = "%s://%s/#/group/new_pwd/%s" %(protocol, domain, token) email_content = template % (group.groupName, admin.qq, link, admin_email, admin_group) start_mail_thread( 'Qjob管理员账户密码重置', email_content, ['*****@*****.**' % admin.qq] ) msg = { "status" : 'success', "msg" : 'email is delivered' } return JsonResponse(msg)