def comment(request): if request.is_ajax(): form = CommentForm(request.POST) if form.is_valid(): blog_id = request.GET.get('blog_id') blog = get_object_or_404(Blog, pk=blog_id) blog.comment_num += 1 blog.save() # pre_comid = form.cleaned_data['pre_comid'] nickname = form.cleaned_data['anickname'] email = form.cleaned_data['bemail'] website = form.cleaned_data['cwebsite'] content = form.cleaned_data['dcontent'] photo = str(random.randint(0, 9)) + '.png' u = User(name=nickname, email=email, website=website, photo=photo) u.save() c = Comment(user=u, blog=blog, content=content, comment_time=timezone.now()) c.save() # sendCommentReply(email) # SendEmail_Comment(nickname,None) return ResponseMsg(True, u'谢谢你的评论') else: return ResponseMsg(False, form.errors.popitem()[1]) else: raise Http404
def signup(request): if request.method == 'POST': context={ 'username': request.POST['username'], 'name': request.POST['name'], 'request':request, } if request.POST['name'] and request.POST['username'] and request.POST['password'] and request.POST['password_confirm']: # d = datetime.datetime.now() if request.POST['password'] == request.POST['password_confirm']: u = User(username=request.POST['username'], password=hashlib.sha224(request.POST['password']+'key').hexdigest(), name=request.POST['name'], # date=d, # date_str=d.strftime('%B %d, %Y') ) u.save() request.session['user'] = u.username request.session['user_obj'] = u return HttpResponseRedirect(reverse('blog:index')) context['error_message'] = 'Password mismatch' else: context['error_message'] = 'Please fill in all fields' return render(request, 'blog/signup.html', context) return render(request, 'blog/signup.html', {'request': request})
def register(request): if request.method == "POST": uf = UserForm(request.POST) if uf.is_valid(): #获取表单信息 username = uf.cleaned_data['username'] email = uf.cleaned_data['email'] password1 = uf.cleaned_data['password1'] password2 = uf.cleaned_data['password2'] filterResult = User.objects.filter(username=username) if len(filterResult) > 0: return render_to_response('register.html', {"errors": "用户名已存在"}) else: errors = [] if (password2 != password1): errors.append("两次输入的密码不一致!") return render_to_response('register.html', {'errors': errors}) #将表单写入数据库 user = User() user.username = username user.password = password1 user.email = email user.save() #返回注册成功页面 return render_to_response('success.html',{'username':username,'operation':"注册"}) else: uf = UserForm() return render_to_response('register.html',{'uf':uf})
def signupc(request): un = request.POST.get('username1') em = request.POST.get('email') pw1 = request.POST.get('password1') pw2 = request.POST.get('password2') print(pw2) print(pw1) filterResult = User.objects.filter(username=un) if len(filterResult) > 0: return render_to_response('CreativeWriting.html', {"errors2": "Username already exists!"}) else: errors = [] if (pw2 != pw1): errors.append("The password entered twice is inconsistent!") return render_to_response('CreativeWriting.html', {'errors2': errors}) # 将表单写入数据库 user = User() user.username = un user.password = pw1 user.email = em user.save() # 返回注册成功页面 return render_to_response('CreativeWriting.html', {"errors": "registration success!"}) return render_to_response('CreativeWriting.html')
def register(request): if request.method == "POST": uf = UserForm(request.POST) if uf.is_valid(): #获取表单信息 username = uf.cleaned_data['username'] password = uf.cleaned_data['password'] email = uf.cleaned_data['email'] #将表单写入数据库 user = User() user.username = username user.password = password user.email = email user.save() # print 'register info:',user.username,user.password,user.email #返回注册成功页面 return render_to_response('success.html', { 'username': username, 'action': '注册' }, context_instance=RequestContext(request)) else: uf = UserForm() return render_to_response('register.html', {'uf': uf})
def signup(request): if request.method=='POST': name=request.POST['email'] password=request.POST['pass'] user = User(username=name,password=password) user.save() return HttpResponseRedirect(reverse('blog:blogindex'))
def post(self, request): print(request.body) bodystr = request.body.decode('utf8') print('bodystr---->', bodystr) bodydict = json.loads(bodystr) print('bodydict---->', bodydict) js_code = bodydict.get('code') print('code------->', js_code) nickname = bodydict.get('nickname') print('nickname------->', nickname) appid = settings.APPID secret = settings.APPSECRET url = f'https://api.weixin.qq.com/sns/jscode2session?appid={appid}&secret={secret}&js_code={js_code}&grant_type=authorization_code' res = requests.get(url) print( res.text ) # {"session_key":"dVs1OcA9mGX+kUdnMRGQFQ==","openid":"omhrO4pE67Nrg2gfPkMGXZjh0v7M"} res_dict = json.loads(res.text) openid = res_dict.get('openid') if not openid: return HttpResponse('Authorize fail') request.session['openid'] = openid request.session['id_authorized'] = True if not User.objects.filter(openid=openid): newuser = User(openid=openid, nickname=nickname) newuser.save() return HttpResponse('Authorize post ok!')
def regist(request): if request.method == "GET": return render(request, 'regist.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') users = User.objects.filter(username=username) # print(users) # print(type(users)) if users.exists(): # return render(request, 'notice.html', context={ 'code': -1, 'msg': "用户名已存在", 'wait': 2, 'url': "/blog/regist" }) user = User() user.username = username user.password = make_pwd(password) user.email = email user.icon = icon user.resgist_time = datetime.today().strftime("%Y/%m/%d/%H/%M/%S") request.session["user_id"] = user.id request.session["user_name"] = user.username #生成token token = str(uuid.uuid4()) user.u_token = token user.save() # 发送邮箱内部的模板并且将token值和username传过去;将邮件发给表单传过来的用户邮箱。 subject, from_email, to = 'html', settings.EMAIL_FROM, email html_content = loader.get_template('activite.html').render({ 'username': username, 'u_token': token }) msg = EmailMultiAlternatives(subject, from_email=from_email, to=[to]) msg.attach_alternative(html_content, "text/html") msg.send() cache.set('token', token, timeout=1800) return render(request, 'notice.html', context={ 'code': 1, 'msg': "注册成功,请尽快去邮箱激活!", 'wait': 3, 'url': "/blog/index" })
def save(self, validated_data): hashedpw = bcrypt.hashpw(validated_data['password'].encode('utf-8'), bcrypt.gensalt()).decode('utf8') user = User(username=validated_data['username'], password=hashedpw) user.save() return user
def signup(request): global forms if request.method == 'POST': name = request.POST.get('Username'); password = request.POST.get('Password'); email = request.POST.get('Email'); user = User(name=name, password=make_password(password), email=email) user.save() return render(request, 'login.html', forms)
def register(request): name=request.POST['Name'] password=request.POST['Password'] hashedpassword=hashlib.md5(password.encode('utf-8')).hexdigest() user=User(name=name,password=hashedpassword) user.save() #categorynum=category.count() #t=loader.get_template("bloglist.html") #c=RequestContext(request,{'posts':post,'category':category}) return HttpResponseRedirect("/blog/"+str(user.id))
def post(self, request, *args, **kwargs): name = request.POST.get('name') pwd = request.POST.get('pwd') user = User() user.name = name user.pwd = encryption_md5(pwd) user.save() return redirect('/login')
def SignUpApi(request): if request.method == 'POST': email = request.POST.get('email') if User.objectl.get(email=email): return JsonResponse({'status':True, 'data':{ 'SignIn': False, 'Message': 'input email is not exist.' }}) user = User(name=request.POST.get('name'),password=make_password(request.POST.get('password')),email=email) user.save() return loginByToken(user) return render(request, 'login.html', forms)
def register(): if current_user.is_authenticated: return redirect(url_for("main.home")) form = RegistrationForm() if form.validate_on_submit(): if form.validate_on_submit(): user = User(username=form.username.data, email=form.email.data) user.set_password(form.password.data) user.save() flash("User registered! Please Log in", "success") return redirect(url_for("users.login")) return render_template("users/register.html", title="Register", form=form)
def mutate(self, info, name, description, mobile, email, posted_by): new_user = UserModel( name=name, description=description, mobile=mobile, email=email, posted_by=posted_by, posted_on=timezone.now(), ) new_user.save() # Notice we return an instance of this mutation return CreateUser(user=new_user)
def register(request): if request.method == 'POST': user_name = request.POST.get('username', '') pass_word_1 = request.POST.get('password_1', '') pass_word_2 = request.POST.get('password_2', '') nick_name = request.POST.get('nickname', '') email = request.POST.get('email', '') avatar = request.FILES.get('avatar') if User.objects.filter(username=user_name): return render(request, 'register.html', {'error': '用户已存在'}) #将表单写入数据库 if (pass_word_1 != pass_word_2): return render(request, 'register.html', {'error': '两次密码请输入一致'}) user = User() if avatar: user.avatar = 'media/' + user_name + '.png' img = Image.open(avatar) size = img.size print(size) # 因为是要圆形,所以需要正方形的图片 r2 = min(size[0], size[1]) if size[0] != size[1]: img = img.resize((r2, r2), Image.ANTIALIAS) # 最后生成圆的半径 r3 = int(r2 / 2) img_circle = Image.new('RGBA', (r3 * 2, r3 * 2), (255, 255, 255, 0)) pima = img.load() # 像素的访问对象 pimb = img_circle.load() r = float(r2 / 2) # 圆心横坐标 for i in range(r2): for j in range(r2): lx = abs(i - r) # 到圆心距离的横坐标 ly = abs(j - r) # 到圆心距离的纵坐标 l = (pow(lx, 2) + pow(ly, 2))**0.5 # 三角函数 半径 if l < r3: pimb[i - (r - r3), j - (r - r3)] = pima[i, j] img_circle.save('blog/static/media/' + user_name + '.png') user.username = user_name user.password = pass_word_1 user.email = email user.nickname = nick_name user.save() #返回注册成功页面 return render(request, 'index_unlog.html') else: return render(request, 'register.html')
def register(req): if req.method == "POST": uf = UserForm(req.POST,req.FILES) if uf.is_valid(): username = uf.cleaned_data['username'] headImg = uf.cleaned_data['headImg'] user = User() user.username = username user.headImg = headImg user.save() print username,'\n', headImg return HttpResponse('ok') else: uf = UserForm() return render_to_response('register.html',{'uf':uf})
def post(self, request): # 接收参数 data = request.POST # 验证数据合法性 form = UserForm(data) if form.is_valid(): # 保存数据库 user = User() user.phone = form.cleaned_data.get('phone') user.password = set_password(form.cleaned_data.get('password')) user.save() # 跳转到登录 return redirect('blog:登录') else: return render(request, 'blog/reg.html', context=form.errors)
def post(self, request, format=None): serializer = RegisterSerializer(data=request.data) if not serializer.is_valid(): return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST) user = User.objects.get(username=serializer.data.get('username')) if user is not None: return Response(status=status.HTTP_400_BAD_REQUEST) if serializer.data.get('password') != serializer.data.get('password1'): return Response(status=status.HTTP_400_BAD_REQUEST) user = User() user.username = serializer.data.get('username') user.set_password(serializer.data.get('password')) user.save() return Response(serializer.data, status=status.HTTP_201_CREATED)
def register(request): if ('email' or 'pwd') not in request.GET: lf = LoginForm() return render_to_response('register.html', {'lf': lf}) lf = LoginForm(request.GET) email = lf.data['email'] pwd = lf.data['pwd'] user = User() user.username = uuid.uuid1() user.email = email user.set_password(pwd) user.desc = 'lazy' user.save() user.user_permissions = [Permission.objects.get(name='Can see news'), Permission.objects.get(name='Can edit news')] return HttpResponseRedirect("/blog/login/")
def register(): if current_user.is_authenticated: return redirect(url_for('main.home')) form = RegistrationForm() if form.validate_on_submit(): hashed_password = bcrypt.generate_password_hash( form.password.data).decode('utf-8') user = User(username=form.username.data, email=form.email.data, password=hashed_password) user.save() flash( f'Account created for {form.username.data}. Then, you can login Now', 'success') return redirect(url_for('users.login')) return render_template('register.html', title='Register', form=form)
def register(request): if request.method == "POST" : uf = UserForm(request.POST,request.FILES) if uf.is_valid(): username = uf.cleaned_data['username'] headImg = uf.cleaned_data['headImg'] user = User() user.name =username user.headImg =headImg user.save() print username,headImg ua = request.META.get('HTTP_USER_AGENT', 'unknown') return HttpResponse("Your browser is %s" % ua) else : uf = UserForm() return render_to_response('register.html',{'uf':uf,'title':'baba'})
def register(request): if request.method == "POST": uf = UserForm(request.POST,request.FILES) if uf.is_valid(): #获取表单信息 username = uf.cleaned_data['username'] headImg = uf.cleaned_data['headImg'] #写入数据库 user = User() user.username = username user.headImg = headImg user.save() return HttpResponse('upload ok!') else: uf = UserForm() return render_to_response('register.html',{'uf':uf})
def regist(req): print req.method if req.method == "POST": uf = UserForm(req.POST, req.FILES) print 'valid? : ', uf.is_valid() if uf.is_valid(): print 'uf is valid' user = User() user.name = uf.cleaned_data['username'] user.headImg = uf.cleaned_data['headImg'] user.save() print user.name return HttpResponse('ok') else: uf = UserForm() return render_to_response('register.html', {'uf':uf})
def regit(req): if req.method == "POST": uf = UserForm(req.POST) if uf.is_valid(): username = uf.cleaned_data['username'] password = uf.cleaned_data['password'] usermail = uf.cleaned_data['usermail'] user = User() user.username = username user.password = password user.usermail = usermail user.save() return HttpResponseRedirect('/login/') else: uf = UserForm() return render(req,'regit.html',{'uf':uf})
def register(request): username = request.POST.get('usernameReg', '') password = request.POST.get('passwordReg', '') email = request.POST.get('emailReg', '') profilePhoto = request.POST.get('profilePhoto', '') articleid = request.POST.get('articleid', '') if username == '' or password == '' or email == '': message = '输入错误了,快说你是怎么进的这个页面!' else: if profilePhoto == '': profilePhoto = '/static/img/deafaultprofilePhoto.png' user = User() user.name = username user.password = password user.email = email user.profilePhoto = profilePhoto try: userInDB = User.objects.get(name=username) except: userInDB = None if userInDB: message = '非常抱歉,你已经注册过了!' else: user.save() message = '哈哈!注册成功了啦(原谅老夫的少女心)!' request.session['name'] = user.name article = Article.objects.get(id=articleid) articles = mdToHtml([article]) try: comments = Comment.objects.filter(article=article) i = 1 for comment in comments: comment.floor = i i += 1 except: comments = None try: username = request.session.get('name') user = User.objects.get(name=username) except: username = None user = None comments = mdToHtml(comments) context = {'config': configList, 'articles': articles, 'comments': comments, 'user': user, 'message': message} return render(request, 'blogs.html', context=context)
def post(self, request): regform = RegForm( request.POST) # 通过注册表单获取用户提交的内容(form表单中的name字段),然后创建实例regform if regform.is_valid(): # 若表单有效性验证成功 username = request.POST.get("email", "") # 获取用户/邮箱/密码信息 email = request.POST.get("email", "") password = request.POST.get("password", "") user = User() # 创建用户实例 user.username = username # 为用户名/邮箱/密码数据属性赋值 user.email = email user.password = password user.password = make_password(password) # 将密码加密处理 user.save() # 保存到数据库(除了用save,也可以用create方式) return render(request, "login.html") # 验证有效之后,返回登录页面 else: return render(request, "reg.html", {"regform": regform}) # 如果表单验证失败,则停留在注册页面
def register(request): if request.method == 'POST': if Constant.SESSION_KEY in request.POST and 'password' in request.POST: un = request.POST['username'] pw = request.POST['password'] user = User.objects.filter(username=un) if user: context = {} context['message'] = '用户名已存在' return render(request,'register.html',context) request.session['username'] = un #save user user = User(username=un,password=pw) user.save() return HttpResponseRedirect('/') else: return render(request,'register.html')
def signin(request): if request.POST: adduser = User() adduser.name = request.POST['username'] if (User.objects.filter(name=request.POST['username'])): msg = 'this name has existed,srory!try a good one!' return render(request, "signup.html", {'msg': msg}) if request.POST['username'] in [ 'Username', 'username' ] and request.POST['password'] == 'password': msg = 'username can not be blank' return render(request, "signup.html", {'msg': msg}) adduser.password = request.POST['password'] adduser.save() msg = 'sign in ok,please log on!' return render(request, "logon.html", {'msg': msg}) return render(request, "signup.html")
def register(): register_form = RegisterForm() if register_form.validate_on_submit(): # Hashing password for security reasons. hashed_password = bcrypt.generate_password_hash( register_form.password.data).decode("utf-8") # Creating new User. new_user = User(username=register_form.username.data, email=register_form.email.data.lower(), password=hashed_password) # Saving User to database. new_user.save() flash("Account has been successfully created. You can now login.", "success") return redirect(url_for("users.login")) return render_template("users/register.html", title="Register", form=register_form)
def register(request): if request.method == "POST": uf = UserForm(request.POST, request.FILES) if uf.is_valid(): print uf.cleaned_data username = uf.cleaned_data['username'] headImg = uf.cleaned_data['headImg'] print username, headImg user = User() user.username = username user.headImg = headImg user.save() return HttpResponse("ok") else: uf = UserForm() return render_to_response('register.html', {'uf': uf})
def register(request): # pass if request.method == "POST": user_name = request.POST.get('username', '') pass_word_1 = request.POST.get('password_1', '') pass_word_2 = request.POST.get('password_2', '') nick_name = request.POST.get('nickname', '') email = request.POST.get('email', '') avatar = request.FILES.get('avatar') if User.objects.filter(username=user_name): return render(request, 'blog/register.html', {'error': '用户已存在'}) if (pass_word_1 != pass_word_2): return render(request, 'blog/register.html', {'error': '两次密码输入不一致'}) user = User() # 将头像设置为圆形 if avatar: user.avatar = 'media/' + user_name + '.png' img = Image.open(avatar) size = img.size r2 = min(size[0], size(1)) if size[0] != size[1]: img = img.resize((r2, r2), Image.ANTIALIAS) r3 = int(r2 / 2) img_circle = Image.new('RGBA', (r3 * 2, r3 * 2), (255, 255, 255, 0)) pima = img.load() pimb = img_circle.load() r = float(r2 / 2) for i in range(r2): for j in range(r2): lx = abs(i - r) ly = abs(j - r) l = (pow(lx, 2) + pow(ly, 2)) ** 0.5 if l < r3: pimb[i - (r - r3), j - (r - r3)] = pima[i, j] img_circle.save('static/media/' + user_name + '.png') user.username = user_name user.password = pass_word_1 user.email = email user.nickname = nick_name user.save() return render(request, 'blog/index_unlogin.html') else: return render(request, 'blog/register.html')
def logon(request): username = request.POST.get('username') password = request.POST.get('password') phone = request.POST.get('phone') yzm = request.POST.get('yzm') # session 取出验证码 yzm1 = request.session.get('yzm') yzm1 = str(yzm1) #print(yzm, yzm1) if yzm == yzm1: user = User() user.user_name = username user.password = md_5(password) user.user_phone = phone user.save() return HttpResponse('注册成功') return HttpResponse('验证码错误')
def register(request): if request.method == "POST": uf = UserForm(request.POST) if uf.is_valid(): #获取表单信息 username = uf.cleaned_data['username'] passworld = uf.cleaned_data['passworld'] email = uf.cleaned_data['email'] #将表单写入数据库 user = User() user.username = username user.passworld = passworld user.email = email user.save() #返回注册成功页面 return render_to_response('blog/success.html',{'username':username}) else: uf = UserForm() return render_to_response('blog/register.html',{'uf':uf})
def regist(request): if request.method == 'POST': email = request.POST.get('email', '') username = request.POST.get('username', '') password = request.POST.get('password', '') rpassword = request.POST.get('rpassword', '') if password != rpassword: return render(request, 'login.html', {'error': '两次密码输入不符!'}) if User.objects.filter(email=email): return render(request, 'login.html', {'error': '用户已存在'}) user = User() user.username = username user.email = email user.password = password user.save() return render(request, 'login.html', {'info': '注册成功,请继续登录操作!'}) else: return render(request, 'login.html', {'error': '数据库异常,请稍后再试!'})
def zhuce(request): if request.method == 'GET': rform = ZhuceForm() return render(request, 'zhuce.html', context={'rform': rform}) else: rform = ZhuceForm(request.POST) if rform.is_valid(): print(rform.cleaned_data) username = rform.cleaned_data.get('username') # 从校验通过的数据中获取对应的参数值 password = rform.cleaned_data.get('password') phone = rform.cleaned_data.get('phone') user = User() user.username = username user.password = password user.phone = phone user.save() else: return render(request, 'zhuce.html', context={'rform': rform}) return HttpResponse('注册成功')
def add_user(): add_user_form = AddUserForm() if add_user_form.validate_on_submit(): user = User() user.username = add_user_form.username.data user.password = add_user_form.password.data user.first_name = add_user_form.first_name.data user.last_name = add_user_form.last_name.data user.biography = add_user_form.biography.data user.save() return redirect("/users") return render_template('user/index.html' , form = add_user_form )
def registered(request): if request.POST: userName = request.POST['userName'] passWord = request.POST['passWord'] # 判断用户名 try: user = User.objects.get(name=userName) except Exception as e: user = None if user: return return_failure(code=2002, msg="当前用户已存在") # if any(book): # return return_failure(code=2002, msg="当前用户已存在") # except: test1 = User(name=userName, password=passWord) test1.save() book = User.objects.get(pk=test1.pk) return return_success(object_to_json(book))
def register(request): if request.method == 'POST': uf = UserForm(request.POST, request.FILES) if uf.is_valid(): #print uf.cleaned_data['username'] #print request.FILES #fp = file('upload/' + uf.cleaned_data['headImage'].name, 'wb') #s = uf.cleaned_data['headImage'].read() #fp.write(s) #fp.close() username = uf.cleaned_data['username'] headImage = uf.cleaned_data['headImage'] user = User() user.usename = username user.headImage = headImage user.save() return HttpResponse('ok') else: uf = UserForm() return render_to_response('register.html',{'uf': uf})
def register(req): if req.method=="POST": uf = UserForm(req.POST,req.FILES) if uf.is_valid(): data = uf.cleaned_data data['password'] = hashlib.md5(data['password']).hexdigest() print data user = User() user.username = data['username'] user.password = data['password'] user.email = data['email'] user.birthday = data['birthday'] user.headimg = data['headimg'] user.desc = data['desc'] user.sex = data['sex'] user.save() return HttpResponse('ok') else: uf = UserForm() return render(req,'register.html',{"uf":uf})
def register(request): if request.method == 'POST': usr = User() usr.username = request.POST.get('username') # usr.password usr.set_password(request.POST.get('password')) usr.email = request.POST.get('email') usr.phone = request.POST.get('phone') usr.bio = request.POST.get('bio') usr.save() image_file = request.FILES.get('image') if image_file: img = ProfileImage() img.file = image_file img.alt_text = request.POST.get('alt_text', 'none') img.description = request.POST.get('img_desc', 'none') img.user = usr img.save() return redirect('login') return render(request, 'register.html')