def save_data(self, f, datos): data = {} if f.is_valid(): use = User() use.username = datos['cedula'] use.cedula = datos['cedula'] use.first_name = datos['first_name'] use.last_name = datos['last_name'] use.sexo = datos['sexo'] use.email = datos['email'] use.telefono = datos['telefono'] use.celular = datos['celular'] use.direccion = datos['direccion'] use.tipo = 0 use.password = make_password(datos['cedula']) use.save() data['resp'] = True data['cliente'] = use.toJSON() grupo = Group.objects.get(name__icontains='cliente') usersave = User.objects.get(id=use.id) usersave.groups.add(grupo) usersave.save() else: data['error'] = f.errors return data
def register(): resp = {'result': 'success', 'status': 200, 'msg': 'success'} data = json.loads(request.data) email = data['email'] if 'email' in data else '' password = data['password'] if 'password' in data else '' checkcode = data['checkcode'] if 'checkcode' in data else '' if checkcode.upper() != session['valicode'].upper(): resp['result'] = 'failed' resp['msg'] = "验证码不正确" resp['status'] = 401 return jsonify(resp) user = User.query.filter_by(email=email).first() if user: resp['result'] = 'failed' resp['msg'] = "邮箱已注册" resp['status'] = 401 return jsonify(resp) new_user = User() new_user.email = email new_user.password_hash = generate_password_hash(password) db.session.add(new_user) db.session.commit() login_user(new_user, True) return jsonify(resp)
def post(self, request): form = RegisterForm(request.POST) if form.is_valid(): username = form.cleaned_data.get('username', '') email = form.cleaned_data.get('email', '') password = form.cleaned_data.get('password', '') users = User() users.username = username users.password = make_password(password) users.email = email users.is_active = False users.save() token = token_confirm.generate_validate_token(username) # message = "\n".join([u'{0},欢迎加入我的博客'.format(username), u'请访问该链接,完成用户验证,该链接1个小时内有效', # '/'.join([settings.DOMAIN, 'activate', token])]) #send_mail(u'注册用户验证信息', message, settings.EMAIL_HOST_USER, [email], fail_silently=False) send_register_email.delay(email=email, username=username, token=token, send_type="register") return JsonResponse({ 'valid': True, 'status': 200, 'message': u"请登录到注册邮箱中验证用户,有效期为1个小时" }) return JsonResponse({ 'status': 400, 'data': form.errors, 'valid': False })
def register2(): if request.method == 'POST': email = request.form.get('email') username = request.form.get('username') password = request.form.get('password') re_password = request.form.get('password2') if password == re_password and len(password) >= 8: i = 6 b = [] while i >= 1: a = random.randint(0, 9) i -= 1 b.append(str(a)) print(b) ve_num = ''.join(b) en_num = generate_password_hash(ve_num) senmail('verify', '*****@*****.**', 'verify', ve_num) ip = input('verify:') if check_password_hash(en_num, ip): user = User() user.email = email user.username = username # user.password = hashlib.sha256(password.encode('utf-8')).hexdigest() # encrypted # 需要加密密碼 user.set_password(password) db.session.add(user) db.session.commit() return 'content' else: print('code is wrong') else: pass return 'fail'
def read_xls(self, request, obj, change): print(obj.file) df = pandas.read_excel(obj.file) print(df) # df.drop([0],inplace=True) # df.columns = ['username','sex','age'] for i in range(0, len(df['学工号'])): username = df.iloc[i, 0] email = df.iloc[i, 1] professor = df.iloc[i, 2] jidian = df.iloc[i, 3] password = 123456 role_id = df.iloc[i, 4] #导入用户信息 role = Role.objects.get(id=role_id) user = User() user.username = username user.role = role user.professor = professor user.email = email user.set_password(password) user.is_active = 1 user.save() #导入绩点信息 rate_jidians = Work_rate_jidian.objects.get(pro_name=professor) id = User.objects.get(username=username).id Work_count.objects.create(usernum=id, count_jidians=jidian, rate_jidians=rate_jidians) return 'success'
def cliente_add(request): data = {} f = UserForm_cliente(request.POST) datos = request.POST if f.is_valid(): with transaction.atomic(): if verificar(f.data['cedula']): use = User() use.username = datos['cedula'] use.cedula = datos['cedula'] use.first_name = datos['first_name'] use.last_name = datos['last_name'] use.sexo = datos['sexo'] use.email = datos['email'] use.telefono = datos['telefono'] use.celular = datos['celular'] use.direccion = datos['direccion'] use.tipo = 0 use.password = make_password(datos['cedula']) use.save() permission = Permission.objects.get(codename='add_venta') permission2 = Permission.objects.get(codename='view_venta') use.user_permissions.add(permission) use.user_permissions.add(permission2) # venta.add_venta # u.user_permissions.add(permission) data['resp'] = 'error' else: f.add_error("cedula", "Numero de Cedula no valido para Ecuador") data['error'] = f.errors else: data['error'] = f.errors return HttpResponse(json.dumps(data), content_type="application/json")
def register(request): r = json.loads(request.body) account = r['account'] password = r['password'] code = r['code'] if judge_type(account) is None: return JsonResponse({'success': False, 'msg': "账号格式有误!"}) # 从redis缓存中读取缓存信息 account唯一 check_code = cache.get(account) print(check_code) # 验证验证码是否正确 if check_code == code: # 新加用户 user = User() user.username = '******' + shuffle_str(True)[0:6] # 判断账号类型 if judge_type(account) == 'phone': user.phone = account else: user.email = account # 密码加密 user.password = encrypt(password) print(user.password) # 保存 user.save() return JsonResponse({'success': True, 'msg': "注册成功!"}) else: return JsonResponse({'success': False, 'msg': "验证码错误!"})
def bindingQQ(request): """ QQ 注册账号 :param request: :return: """ if request.method == 'POST': openid = request.POST.get('openid') figureurl_qq_1 = request.POST.get('figureurl_qq_1') nickname = request.POST.get('nickname') password = request.POST.get('password') password1 = request.POST.get('password1') email = request.POST.get('email') if password != password1: return render( request, 'pc/qqregister.html', { 'openid': openid, 'figureurl_qq_1': figureurl_qq_1, 'nickname': nickname, 'error': '两次密码不一致' }) else: User.objects.filter(email=email).exists() if User.objects.filter(email=email).exists(): return render( request, 'pc/qqregister.html', { 'openid': openid, 'figureurl_qq_1': figureurl_qq_1, 'nickname': nickname, 'error': '邮箱已存在' }) else: user = User() user.username = nickname user.email = email user.user_image = figureurl_qq_1 user.is_staff = False user.is_superuser = False user.is_active = True user.password = make_password(password1) user.save() qq = OAuthQQ() user_id = get_object_or_404(User, email=email).id qq.user_id = user_id msg = UserMessage() msg.user_id = user_id msg.to_user = User.objects.get(is_superuser=True) msg.message = '欢迎加入本站,在使用过程中有什么疑问,请联系管理员,Email: <a target="_blank" href="http://mail.qq.com/cgi-bin/qm_share?t=qm_mailme&email=iuzv5O3g4_T748rs7_Tt4OPk__Ok6eXn" style="text-decoration:none;">[email protected]</a>' msg.has_read = False msg.is_supper = True msg.save() qq.qq_openid = openid qq.nickname = nickname qq.figureurl_qq = figureurl_qq_1 qq.save() user = authenticate(request, username=email, password=password) login(request, user) return HttpResponseRedirect(reverse('home'))
def bindingQQ(request): """ QQ 注册账号 :param request: :return: """ if request.method == 'POST': openid = request.POST.get('openid') figureurl_qq_1 = request.POST.get('figureurl_qq_1') nickname = request.POST.get('nickname') password = request.POST.get('password') password1 = request.POST.get('password1') email = request.POST.get('email') if password != password1: return render( request, 'pc/qqregister.html', { 'openid': openid, 'figureurl_qq_1': figureurl_qq_1, 'nickname': nickname, 'error': '两次密码不一致' }) else: User.objects.filter(email=email).exists() if User.objects.filter(email=email).exists(): return render( request, 'pc/qqregister.html', { 'openid': openid, 'figureurl_qq_1': figureurl_qq_1, 'nickname': nickname, 'error': '邮箱已存在' }) else: user = User() user.username = nickname user.email = email user.user_image = figureurl_qq_1 user.password = make_password(password1) user.save() qq = OAuthQQ() user_id = get_object_or_404(User, email=email).id qq.user_id = user_id msg = UserMessage() msg.user_id = user_id msg.to_user = User.objects.get(username='******') msg.message = '欢迎加入本站,在使用过程中有什么疑问,请联系管理员' msg.has_read = False msg.is_supper = True msg.save() qq.qq_openid = openid qq.nickname = nickname qq.figureurl_qq = figureurl_qq_1 qq.save() user = authenticate(request, username=email, password=password) login(request, user) return HttpResponseRedirect(reverse('home'))
def post(self, request): # 1.获取参数 user_num = request.POST.get('user_num') password = request.POST.get('pwd') professor = request.POST.get('cpwd') email = request.POST.get('email') role_id = request.POST.get('loc') print(role_id) # 2.校验参数完整性 if not all([user_num, password, professor, email, role_id]): return render(request, 'register.html', {'errmsg': '数据不完整,请重新输入'}) # 2.1校验邮箱是否合法 # 校验邮箱 if not re.match(r'^[a-z0-9][\w.\-]*@[a-z0-9\-]+(\.[a-z]{2,5}){1,2}$', email): return render(request, 'register.html', {'errmsg': '邮箱格式不正确'}) # 2.2校验用户是否存在 try: user = User.objects.get(user_num=user_num) except User.DoesNotExist: # 用户不存在 user = None if user: # 用户名已存在 return render(request, 'register.html', {'errmsg': '用户名已存在'}) # 3.业务处理,进行注册操作 role = Role.objects.get(id=role_id) user = User() user.username = user_num user.role = role user.professor = professor user.email = email user.set_password(password) user.is_active = 0 user.save() # 注册成功需要通过邮箱返回激活链接 # 使用itsdangerous生成激活的token信息 seeializer = Serializer(settings.SECRET_KEY, 3600) info = {'confirm': user.id} # 进行加密 token = seeializer.dumps(info) # 转换类型 token = token.decode() # 组织邮件内容 send_mail_register(email, user_num, token) # 返回应答 # 4.返回响应 return render(request, 'login.html')
def register(cls, user_name, real_name, password, email, telephone, role_id, job): if UserManager.verify_existence(user_name): return jsonify({"code": 400, "message": "用户已存在,请更换用户名"}) user = User() user.user_name = user_name user.real_name = real_name user.email = email user.telephone = telephone user.role_id = role_id user.job = job user.create_time = TimeManager.now() user.pwd = password db.session.add(user) user.save() return jsonify({"code": 200, "message": "注册成功"})
def register(): if request.method == 'POST': username = request.form.get('username') password = request.form.get('password') repassword = request.form.get('repassword') phone = request.form.get('phone') email = request.form.get('email') if password == repassword: user = User() user.username = username # 使用自带的函数实现加密:generate_password_hash user.password = generate_password_hash(password) user.phone = phone user.email = email db.session.add(user) db.session.commit() return redirect(url_for('user.index')) return render_template('user/register.html')
def register(): """用户注册""" if request.method == "POST": username = request.form.get("username") password = request.form.get("password") confirm_password = request.form.get('confirmpwd') email = request.form.get('email') phone = request.form.get('phone') if password == confirm_password: user = User() user.username = username user.password = generate_password_hash(password) user.phone = phone user.email = email db.session.add(user) db.session.commit() return redirect(url_for('user.login')) return render_template('user/register.html')
def register(): if request.method == 'POST': username = request.form.get('username') password = request.form.get('password') repassword = request.form.get('repassword') phone = request.form.get('phone') email = request.form.get('email') if password == repassword: user = User() user.username = username user.password = hashlib.md5(password.encode('utf-8')).hexdigest() user.phone = phone user.email = email db.session.add(user) db.session.commit() return redirect(url_for('user.index')) else: return '二次密码不一致,请重新输入' return render_template('user/register.html')
def register(): if request.method == 'POST': username = request.form.get('username') password = request.form.get('password') repassword = request.form.get('repassword') phone = request.form.get('phone') email = request.form.get('email') if password == repassword: # 注册用户 user = User() user.username = username # 使用自带的函数实现加密:generate_password_hash user.password = generate_password_hash(password) print(password) user.phone = phone user.email = email # 添加并提交 db.session.add(user) db.session.commit() return '注册成功!' return render_template('user/register.html')
def post(self, request): username = request.POST.get("user_name") password = request.POST.get("pwd") email = request.POST.get('email') allow = request.POST.get('allow') if not all([username, password, email]): return render(request, 'register.html', {'errmsg': '信息填写不完整'}) if allow != 'on': return render(request, 'register.html', {'errmsg': '请同意协议'}) try: user = User.objects.get(username=username) except Exception as e: print(e) user = None if user is not None: return render(request, 'register.html', {'errmsg': '用户已存在'}) user = User() user.username = username user.password = password user.email = email user.save() return redirect(reverse('user:login'))
def register(): user, types = user_type() if request.method == 'POST': username = request.form.get('username') password = request.form.get('password') repassword = request.form.get('repassword') phone = request.form.get('phone') email = request.form.get('email') if repassword == password: user = User() user.username = username user.password = generate_password_hash(password) user.phone = phone user.email = email db.session.add(user) db.session.commit() return redirect(url_for('user.index')) else: return render_template('user/register.html', msg='两次密码不一致', types=types) return render_template('user/register.html', types=types)