def register(request): if request.method == 'GET': return httputils.render_html(request,'gobang/register.html', {}) else: email = request.POST.get('email', default = None) passwd = request.POST.get('passwd', default = None) username = request.POST.get('username', default = None) validation_code = request.POST.get('validation_code', default = None) #check input not none for item in (email, passwd,username,validation_code): if item is None: return render(request, 'gobang/register.html',{'error_msg':'input has none'}) #check validation code right server_validation_code = validation_cache.get(email) if server_validation_code is None or server_validation_code != validation_code: return render(request, 'gobang/register.html',{'error_msg':'validation code not right'}) #insert db and use model to check input format right added_person = Person(username=username,passwd=passwd,email=email) try: added_person.save() except Exception as e: #record exception gobang_logger.error("insert db error, {0}".format(e)) return render(request, 'gobang/register.html',{'error_msg':str(e)}) #set sessions and redirect request.session['login'] = True request.session['pk'] = added_person.pk request.session['username'] = added_person.username return HttpResponseRedirect('/gobang/index')
def register(request): if request.method == 'GET': return httputils.render_html(request, 'gobang/register.html', {}) else: email = request.POST.get('email', default=None) passwd = request.POST.get('passwd', default=None) username = request.POST.get('username', default=None) validation_code = request.POST.get('validation_code', default=None) #check input not none for item in (email, passwd, username, validation_code): if item is None: return render(request, 'gobang/register.html', {'error_msg': 'input has none'}) #check validation code right server_validation_code = validation_cache.get(email) if server_validation_code is None or server_validation_code != validation_code: return render(request, 'gobang/register.html', {'error_msg': 'validation code not right'}) #insert db and use model to check input format right added_person = Person(username=username, passwd=passwd, email=email) try: added_person.save() except Exception as e: #record exception gobang_logger.error("insert db error, {0}".format(e)) return render(request, 'gobang/register.html', {'error_msg': str(e)}) #set sessions and redirect request.session['login'] = True request.session['pk'] = added_person.pk request.session['username'] = added_person.username return HttpResponseRedirect('/gobang/index')
def send_validation_code_email(request): if request.method == 'POST': email = request.POST.get('email', default = None) #check cache print email validation_code = validation_cache.get(email) if validation_code: print "already",validation_code return httputils.make_json_response({"message":"validation code already","error_code":"1"}) else: random_number = utils.random_code(6) #send email #from django.core.mail import send_mail #send_mail('Subject here', 'Here is the message.', '*****@*****.**',['*****@*****.**'], fail_silently=False) print "new_random", random_number #set number to cache validation_cache.set(email, random_number, settings.VALIDATION_TIME) return httputils.make_json_response({"error_code":"0"}) else: return HttpResponseNotFound()
def send_validation_code_email(request): if request.method == 'POST': email = request.POST.get('email', default=None) #check cache print email validation_code = validation_cache.get(email) if validation_code: print "already", validation_code return httputils.make_json_response({ "message": "validation code already", "error_code": "1" }) else: random_number = utils.random_code(6) #send email #from django.core.mail import send_mail #send_mail('Subject here', 'Here is the message.', '*****@*****.**',['*****@*****.**'], fail_silently=False) print "new_random", random_number #set number to cache validation_cache.set(email, random_number, settings.VALIDATION_TIME) return httputils.make_json_response({"error_code": "0"}) else: return HttpResponseNotFound()