def user_register(request): if request.method == 'GET': return render(request, 'UserRegister.html') elif request.method == 'POST': username = request.POST.get('username') user = UserModel() user.u_name = username token = str(uuid.uuid4()) user.u_token = token user.save() return HttpResponse('注册成功%s' % token)
def user_register(request): if request.method == 'GET': return render(request, 'UserRegister.html') elif request.method == 'POST': username = request.POST.get("username") password = request.POST.get("password") user = UserModel() user.u_name = username user.u_password = password token = str(uuid.uuid4()) user.u_token = token user.save() return HttpResponse('注册成功')
def user_zhuce(request): if request.method == 'GET': return render(request,'user_zhuce.html') elif request.method == 'POST': username = request.POST.get('username') user = UserModel() user.u_name = username token = genrate_token(request.META.get('REMDTE_ADDR')) user.u_token = token user.save() response = HttpResponse('注册成功') response.set_cookie('token',token) return response
def do_user_register(request): u_name = request.POST.get('username') u_password = request.POST.get('password') u_age = request.POST.get('age') user = UserModel() user.u_name = u_name user.u_password = password_sec(u_password) user.u_age = u_age # u_token 唯一标识 # 时间 + 随机数 + 公司域名 + ip信息 # 时间 + 域名 token = generate_token() user.u_token = token user.save() response = HttpResponseRedirect(reverse("app:user_info")) response.set_cookie("utoken", token) return response
def user_register(request): if request.method == "GET": return render(request, 'UserRegister.html') elif request.method == 'POST': username = request.POST.get('username') password = request.POST.get('password') user = UserModel() user.u_name = username user.u_password = password token = generate_token(request.META.get("REMOTE_ADDR"), username) user.u_token = token user.save() response = HttpResponse('注册成功') response.set_cookie('token', token) return response
def post(self): parse = parser.parse_args() username = parse.get("username") password = parse.get("password") email = parse.get("email") print('-------------------') print(username) user = UserModel() user.u_name = username #generate_password_hash(password=password) 加密 user.u_password = password user.u_email = email token = str(uuid.uuid4()) user.u_token = token try: db.session.add(user) db.session.commit() # 思考set方法中的参数分别是谁? timeout指的是缓存的生存时间 cache.set(token, user.id, timeout=400) msg = Message(subject="Tpp激活邮件", recipients=[email], sender="*****@*****.**") body_html = render_template( "UserActive.html", username=username, active_url='http://localhost:5002/account/?u_token=' + token) msg.html = body_html mail.send(msg) except Exception as e: return {"returnCode": "200", "msg": str(e)} return {"returnCode": "200", "msg": "ok", "returnValue": user}