def updateUserInfoForm(request): if 'useruuid' in request.session: updateLoginForm = UpdateLoginForm(request.POST) if updateLoginForm.is_valid(): oldpwd = updateLoginForm.cleaned_data['oldpwd'] newpwd = updateLoginForm.cleaned_data['newpwd'] renewpwd = updateLoginForm.cleaned_data['renewpwd'] user_data = Users.objects.get(useruuid=str(request.session['useruuid'])) trans_data = user_data.to_dict() trans_data['transfer_enable'] = trans_data['transfer_enable']/1000/1000/1024 trans_data['transfer_used'] = (trans_data['up_transfer'] + trans_data['down_transfer'])/1000/1000/1024 trans_data['transfer_last'] = trans_data['transfer_enable']-trans_data['transfer_used'] trans_data['last_online_ts'] = TimeUtils.getDatetimeFromTS(trans_data['last_online_ts']) trans_data['updateSSPwdForm'] = UpdateSSPwdForm() trans_data['updateLoginForm'] = UpdateLoginForm() encrptuserpwd = EncrptyUtils.getMd5(oldpwd+str(user_data.register_ts)) if encrptuserpwd == user_data.encrptuserpwd: if newpwd==renewpwd: user_data.encrptuserpwd = EncrptyUtils.getMd5(newpwd+str(user_data.register_ts)) user_data.save() trans_data['scsmsg']='更新密码成功' else: trans_data['errmsg']='两次输入的密码不一致' return render_to_response('users/users_front_update.html',trans_data) else: trans_data['errmsg']='原始密码输入错误,密码未修改成功' return render_to_response('users/users_front_update.html',trans_data) else: form = LoginForm() return render_to_response('login.html',{'form':form},context_instance = RequestContext(request))
def loginForm(request): if request.method=='POST': form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] userpwd = form.cleaned_data['userpwd'] user_data = None try: user_data = Users.objects.get(username=username) except Exception,e: return render_to_response('login.html',{'form':form,'errormsg':'您输入的账号有误'}) if not user_data.actived: return render_to_response('login.html',{'form':form,'errormsg':'您输入的账号未激活,请登陆您的注册邮箱'+str(user_data.email)+'进行激活','errorlink':'#','reactiveemail':str(user_data.email)}) encrptuserpwd = EncrptyUtils.getMd5(userpwd+str(user_data.register_ts)) if user_data.encrptuserpwd == encrptuserpwd: trans_data = user_data.to_dict() trans_data['transfer_enable'] = trans_data['transfer_enable']/1000/1000/1024 trans_data['transfer_used'] = (trans_data['up_transfer'] + trans_data['down_transfer'])/1000/1000/1024 trans_data['transfer_last'] = trans_data['transfer_enable']-trans_data['transfer_used'] trans_data['last_online_ts'] = TimeUtils.getDatetimeFromTS(trans_data['last_online_ts']) trans_data['transfer_used_scale'] = trans_data['transfer_used']/trans_data['transfer_enable']*100 request.session['useruuid'] = trans_data['useruuid'] return render_to_response('users/users_front.html',trans_data) else: return render_to_response('login.html',{'form':form,'errormsg':'您输入的密码有误,请重新输入'})
def adminLoginForm(request): adminLoginForm = AdminLoginForm(request.POST) if adminLoginForm.is_valid(): adminusername = adminLoginForm.cleaned_data['adminusername'] adminuserpwd = adminLoginForm.cleaned_data['adminuserpwd'] if adminusername =='admin' and adminuserpwd == EncrptyUtils.getMd5('123qwe'): return render_to_response('adminmgr/admin_front.html') else: return render_to_response('adminmgr/admin_login.html',{'form':adminLoginForm})
def updateUserInfoForm(request): if 'useruuid' in request.session: updateLoginForm = UpdateLoginForm(request.POST) if updateLoginForm.is_valid(): oldpwd = updateLoginForm.cleaned_data['oldpwd'] newpwd = updateLoginForm.cleaned_data['newpwd'] renewpwd = updateLoginForm.cleaned_data['renewpwd'] user_data = Users.objects.get( useruuid=str(request.session['useruuid'])) trans_data = user_data.to_dict() trans_data['transfer_enable'] = trans_data[ 'transfer_enable'] / 1000 / 1000 / 1024 trans_data['transfer_used'] = ( trans_data['up_transfer'] + trans_data['down_transfer']) / 1000 / 1000 / 1024 trans_data['transfer_last'] = trans_data[ 'transfer_enable'] - trans_data['transfer_used'] trans_data['last_online_ts'] = TimeUtils.getDatetimeFromTS( trans_data['last_online_ts']) trans_data['updateSSPwdForm'] = UpdateSSPwdForm() trans_data['updateLoginForm'] = UpdateLoginForm() encrptuserpwd = EncrptyUtils.getMd5(oldpwd + str(user_data.register_ts)) if encrptuserpwd == user_data.encrptuserpwd: if newpwd == renewpwd: user_data.encrptuserpwd = EncrptyUtils.getMd5( newpwd + str(user_data.register_ts)) user_data.save() trans_data['scsmsg'] = '更新密码成功' else: trans_data['errmsg'] = '两次输入的密码不一致' return render_to_response('users/users_front_update.html', trans_data) else: trans_data['errmsg'] = '原始密码输入错误,密码未修改成功' return render_to_response('users/users_front_update.html', trans_data) else: form = LoginForm() return render_to_response('login.html', {'form': form}, context_instance=RequestContext(request))
def adminLoginForm(request): adminLoginForm = AdminLoginForm(request.POST) if adminLoginForm.is_valid(): adminusername = adminLoginForm.cleaned_data['adminusername'] adminuserpwd = adminLoginForm.cleaned_data['adminuserpwd'] if adminusername == 'admin' and adminuserpwd == EncrptyUtils.getMd5( '123qwe'): return render_to_response('adminmgr/admin_front.html') else: return render_to_response('adminmgr/admin_login.html', {'form': adminLoginForm})
def loginForm(request): if request.method == 'POST': form = LoginForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] userpwd = form.cleaned_data['userpwd'] user_data = None try: user_data = Users.objects.get(username=username) except Exception, e: return render_to_response('login.html', { 'form': form, 'errormsg': '您输入的账号有误' }) if not user_data.actived: return render_to_response( 'login.html', { 'form': form, 'errormsg': '您输入的账号未激活,请登陆您的注册邮箱' + str(user_data.email) + '进行激活', 'errorlink': '#', 'reactiveemail': str(user_data.email) }) encrptuserpwd = EncrptyUtils.getMd5(userpwd + str(user_data.register_ts)) if user_data.encrptuserpwd == encrptuserpwd: trans_data = user_data.to_dict() trans_data['transfer_enable'] = trans_data[ 'transfer_enable'] / 1000 / 1000 / 1024 trans_data['transfer_used'] = ( trans_data['up_transfer'] + trans_data['down_transfer']) / 1000 / 1000 / 1024 trans_data['transfer_last'] = trans_data[ 'transfer_enable'] - trans_data['transfer_used'] trans_data['last_online_ts'] = TimeUtils.getDatetimeFromTS( trans_data['last_online_ts']) trans_data['transfer_used_scale'] = trans_data[ 'transfer_used'] / trans_data['transfer_enable'] * 100 request.session['useruuid'] = trans_data['useruuid'] return render_to_response('users/users_front.html', trans_data) else: return render_to_response('login.html', { 'form': form, 'errormsg': '您输入的密码有误,请重新输入' })
def registerForm(request): if request.method == 'POST': form = RegisterForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] userpwd = form.cleaned_data['userpwd'] email = form.cleaned_data['email'] reuserpwd = form.cleaned_data['reuserpwd'] register_ts = TimeUtils.getTimeStamp() user_data = Users( useruuid=StrUtils.getUUUID(username + str(register_ts)), username=username, email=email, encrptuserpwd=EncrptyUtils.getMd5(userpwd + str(register_ts)), sspwd=StrUtils.getRandomStr(6), register_ts=register_ts, last_online_ts=register_ts, up_transfer=0, down_transfer=0, port=int( Users.objects.aggregate(Max('port'))['port__max'] or 49999) + StrUtils.getRandomNum(1, 3), switch=1, enable=1, usertype=0, actived=0, ) user_data.save() #t1 = threading.Thread(target=send_mail,args=('ss active ', 'http://127.0.0.1:8000/ please click it and active your account', '*****@*****.**',[email], fail_silently=False)) #t1.start() send_mail( 'ss active ', 'http://127.0.0.1:8000/ please click it and active your account', '*****@*****.**', [email], fail_silently=False) return render_to_response('users/register_success.html', {'username': username}) else: return render_to_response('register.html', {'form': form}) else: form = RegisterForm() return render_to_response(request, 'register.html', {'form': form})
def registerForm(request): if request.method == 'POST': form = RegisterForm(request.POST) if form.is_valid(): username = form.cleaned_data['username'] userpwd = form.cleaned_data['userpwd'] email = form.cleaned_data['email'] reuserpwd = form.cleaned_data['reuserpwd'] register_ts = TimeUtils.getTimeStamp() user_data = Users( useruuid = StrUtils.getUUUID(username+str(register_ts)), username = username, email = email, encrptuserpwd = EncrptyUtils.getMd5(userpwd+str(register_ts)), sspwd = StrUtils.getRandomStr(6), register_ts = register_ts, last_online_ts = register_ts, up_transfer = 0, down_transfer = 0, port = int(Users.objects.aggregate(Max('port'))['port__max'] or 49999)+StrUtils.getRandomNum(1,3), switch = 1, enable = 1, usertype = 0, actived=0, ) user_data.save() #t1 = threading.Thread(target=send_mail,args=('ss active ', 'http://127.0.0.1:8000/ please click it and active your account', '*****@*****.**',[email], fail_silently=False)) #t1.start() send_mail('ss active ', 'http://127.0.0.1:8000/ please click it and active your account', '*****@*****.**',[email], fail_silently=False) return render_to_response('users/register_success.html',{'username':username}) else: return render_to_response('register.html',{'form':form}) else: form = RegisterForm() return render_to_response(request, 'register.html', {'form': form})