def user_register(request): if request.method == "GET": data = { "title": '用户注册', } return render(request, 'user/user_register.html', context=data) elif request.method == "POST": u_name = request.POST.get("u_name") u_email = request.POST.get("u_email") u_password = request.POST.get("u_password") print(u_password) u_icon = request.FILES.get("u_icon") user = UserModel() user.u_name = u_name user.u_email = u_email user.u_icon = u_icon user.set_password(u_password) user.save() request.session['user_id'] = user.id # 发送邮件 token生成策略 自己写,使用 uuid, 引入第三方库 , secrets库 python 3.6 token = str(uuid.uuid4()) cache.set(token, user.id, timeout=60 * 60) send_mail_learn(u_name, u_email, token) return redirect(reverse('axf:mine'))
def user_register(request): if request.method == "GET": data = { 'title': '用户注册', } return render(request, 'main/user_register.html', context=data) elif request.method == "POST": u_name = request.POST.get("u_name") u_email = request.POST.get("u_email") u_password = request.POST.get("u_password") u_icon = request.FILES.get("u_icon") user = UserModel() user.u_name = u_name user.u_email = u_email user.u_icon = u_icon user.set_password(u_password) user.save() request.session['user_id'] = user.id # 发送邮件 # token = str(uuid.uuid4()) token = secrets.token_hex(16) cache.set(token, user.id, timeout=60) send_mail_learn(u_name, u_email, token) return redirect(reverse('axf:mine'))
def register(request): if request.method == "GET": data = { 'title': '用户注册', } return render(request, 'register/register.html', context=data) elif request.method == "POST": u_name = request.POST.get("u_name") u_email = request.POST.get("u_email") u_password = request.POST.get("u_password") u_password2 = request.POST.get("u_password2") u_icon = request.FILES.get("u_icon") if u_password == u_password2: user = UserModel() user.u_name = u_name user.u_email = u_email user.u_icon = u_icon user.set_password(u_password) print("save") user.save() request.session['user_id'] = user.id token = str(uuid.uuid4()) cache.set(token, user.id) return redirect(reverse('second:home_logined')) else: return render(request, 'register/register.html')
def user_register(request): if request.method == 'GET': return render(request,'App/user/user_register.html') elif request.method == 'POST': username = request.POST.get('username') password = request.POST.get('password') email = request.POST.get('email') icon = request.FILES.get('icon') user = UserModel() user.u_name = username user.u_email = email # user.u_password = password user.set_password(password) user.u_icon = icon user.save() # temp = loader.get_template('App/active_email.html') # # token = str(uuid.uuid4()) # # cache.set(token,user.id,timeout=10*60) # # temp_content = temp.render({'username':username,'active_url':'http://127.0.0.1:8004/app/useractive/?u_token='+token}) # # send_mail('项目激活邮件','','*****@*****.**',[email,],html_message=temp_content) request.session['username'] = username request.session.flush() return redirect(reverse('app:mine'))
def post(self, request): u_username = request.POST.get("u_username") u_email = request.POST.get("u_email") u_password = request.POST.get("u_password") u_icon = request.FILES.get("u_icon") user = UserModel() user.u_name = u_username user.u_password = u_password user.u_email = u_email user.u_icon = u_icon user.save() # 生成token 时间 + ip + 随机数 # uuid token = str(uuid.uuid4()) cache.set(token, user.id, timeout=60 * 60 * 24) active_url = "http://localhost:8002/axf/active/?token=" + token send_mail_to_asy.delay(u_username, active_url, u_email) # request.session["user_id"] = user.id response = redirect(reverse("axf:user_login")) return response
def user_register(request): if request.method == "GET": return render(request, 'user/user_register.html') elif request.method == "POST": try: username = request.POST.get("username") password = request.POST.get("password") email = request.POST.get("email") icon = request.FILES.get("icon") print(username) print(password) print(email) print(icon) user = UserModel() user.username = username # 添加数据安全 password = generate_password(password) print(password) user.password = password user.email = email user.icon = icon user.save() request.session["user_id"] = user.id return redirect(reverse("axf:mine")) except Exception as e: return redirect(reverse("axf:user_register")) else: raise Exception("不被支持的请求")
def register(request): method = request.method if method =='GET': return render(request, 'user/register.html') elif method == 'POST': uername = request.POST.get('name') password = request.POST.get('password') email = request.POST.get('email') imgFile = request.FILES.get('imgFile') user = UserModel() user.u_name = uername user.u_password = password user.u_email = email user.u_img = imgFile user.save() return HttpResponseRedirect(reverse('axf:login'))
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 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 image_field(request): if request.method == 'GET': return render(request, 'image_field.html') elif request.method == 'POST': username = request.POST.get('username') icon = request.FILES.get('icon') user = UserModel() user.u_name = username user.u_icon = icon user.save() return HttpResponse('上传成功 %d' % user.id)
def user_register(request): if request.method == "GET": data = { "title": '用户注册', } return render(request, 'register.html', context=data) elif request.method == "POST": u_name = request.POST.get("u_name") u_email = request.POST.get("u_email") u_password = request.POST.get("u_password") u_icon = request.FILES.get("u_icon") user = UserModel() user.u_name = u_name user.u_email = u_email user.u_icon = u_icon user.set_password(u_password) user.save() request.session['user_id'] = user.id return redirect(reverse('App:home'))
def user_register(request): if request.method == 'GET': return render(request, "App/user/user_register.html") elif request.method == "POST": username = request.POST.get("username") password = request.POST.get("password") email = request.POST.get("email") #上传的文件用File icon = request.FILES.get("icon") user = UserModel() user.u_name = username # user.u_password = password user.set_password(password=password) user.u_email = email user.u_icon = icon user.save() # 发送激活邮件 token = str(uuid.uuid4()) cache.set(token, user.id, timeout=10 * 60) template = loader.get_template("App/ActiveEmail.html") template_content = template.render({ "username": username, "active_url": "http://127.0.0.1:8000/app/user_active/?u_token=" + token }) send_mail("AXF高级VIP激活", "", "*****@*****.**", [ email, ], html_message=template_content) # 存入session中 request.session["username"] = username return redirect(reverse("app:mine"))
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 api_add(request): # user = UserModel(username='******',password='******') # user.save() # UserModel.objects.create(**{'username':'******','password':'******'}) # return HttpResponse("数据增") firstname = ["赵", "钱", "孙", "李", "周", "吴", "郑", "王", "西门"] lastname = ['三', '二狗', '刚', '华', '珍', '强', '麻子'] users = [] for i in range(100): name = firstname[randint(0, 8)] + lastname[randint(0, 6)] + str( randint(11111, 22222)) password = str(randint(111111, 999999)) users.append(UserModel(username=name, password=password)) UserModel.objects.bulk_create(users) return HttpResponse('添加')
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 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 put(self): parser = parse.parse_args() username = parser.get("username") password = parser.get("password") email = parser.get("email") user = UserModel() user.u_name = username user.u_password = generate_password_hash(password=password) user.u_email = email user.save() u_token = str(uuid.uuid4()) cache.set(u_token, user.id, timeout=60) msg = Message(subject="TestTppActive",sender="*****@*****.**",recipients=["*****@*****.**"]) html = render_template("UserActivate.html", username=username, active_url="http://localhost:5000/users/?action=active&u_token=%s"%u_token) msg.html = html mail.send(msg) return {"msg":"ok","data":user}
def image_field(request): if request.method == "GET": return render(request, 'image_field.html') elif request.method == "POST": username = request.POST.get("username") icon = request.FILES.get("icon") user = UserModel() user.u_name = username user.u_icon = icon user.save() return HttpResponse("上传成功%d" % user.id)
def user_register(request): if request.method == 'GET': return render(request, 'user_register.html') elif request.method == 'POST': icon = request.FILES.get('icon') username = request.POST.get('username') password = request.POST.get('password') user = UserModel() user.u_name = username password = genart_password(password) user.u_password = password user.u_icon = icon user.save() response = HttpResponse('注册成功') response.set_cookie('username', username) return response
def register_user(): if request.method == 'GET': return render_template('register.html') if request.method == 'POST': user = UserModel() user.username = request.form.get('username') user.email = request.form.get('email') user.password = request.form.get('password') # user.user_id = request.form.get('user_id') if len(user.username) == 0 or len(user.email) == 0 or len( user.password) == 0: context = '请填写完整' return render_template('register.html', context=context) else: user.password = generate_password_hash(user.password) db.session.add(user) db.session.commit() return redirect(url_for('user.login_user'))
def image_field(request): if request.method == "GET": return render(request, 'image_field.html') elif request.method == "POST": username = request.POST.get("username") icons = request.FILES.getlist("icon") for icon in icons: user = UserModel() user.u_name = username user.u_icon = icon user.save() # destination = open(BASE_DIR + '/static/upload/' + icon.name, 'wb+') # for part in icon.chunks(): # destination.write(part) # destination.close() return HttpResponse("上传成功")
def post(self): #注册 #获取客户端提交过来的东西 parse = parser.parse_args() username = parse.get('username') password = parse.get('password') email = parse.get('email') user = UserModel() user.name = username user.passwd = generate_password_hash(password) user.email = email #注册时设置token的值(唯一标识一个用户) user.token = str(uuid.uuid4()) try: db.session.add(user) db.session.commit() #临时存储5分钟,在5分钟之内激活有效(临时存储user.token,user.id) cache.set(user.token, user.id, timeout=300) #给指定的邮箱发送邮件 msg = Message(subject='用户激活', sender='*****@*****.**', recipients=[email]) #邮箱内容 msg.html = render_template( 'email_active.html', username=username, active_url='http://127.0.0.1:5000/urr/?u_token=%s' % user.token) #发送 mail.send(msg) except Exception as e: return {'returnCode': '-1', 'msg': e} return {'returnCode': '0', 'msg': 'success', 'returnValue': user}
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}
def post(self): username = request.form.get("username") password = request.form.get("password") email = request.form.get("email") icon = request.form.get("icon") data = {"msg": "ok", "status": "422"} if not username or not password: data["msg"] = "參數不正確" return jsonify(data), 422 user = UserModel() user.username = username user.password = generate_password(password) user.email = email user.icon = icon try: db.session.add(user) db.session.commit() data["status"] = "201" except Exception as e: data["status"] = "901" data["msg"] = str(e) return jsonify(data), 201