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 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 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 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 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 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(): if request.method == 'POST': username = request.form.get('username') password = request.form.get('password') repassword = request.form.get('repassword') phone = request.form.get('phone') if password == repassword: # 注册用户 user = User() user.username = username user.password = hashlib.sha256( password.encode('utf-8')).hexdigest() user.phone = phone # 添加并提交 db.session.add(user) db.session.commit() return redirect(url_for('user.user_center')) 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 # 使用自带的函数实现加密: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 post(self): args = self.parser.parse_args() username = args.get(arg_username,'') password = args.get(arg_password,'') if username and password: try: user = User() user.username = username user.passwd = password db.session.add(user) db.session.commit() data = {'user': user} result = { 'data': data } return result except: db.session.rollback()
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 save_data(self, f): data = {} if f.is_valid(): f.save(commit=False) if verificar(f.data['cedula']): cli = f.save() data['resp'] = True data['empleado'] = cli.toJSON() if cli.cargo == 0 or 1 or 2: us = User() us.cedula = cli.cedula us.username = cli.cedula us.set_password(cli.cedula) us.save() else: f.add_error("cedula", "Numero de Cedula no valido para Ecuador") data['error'] = f.errors else: data['error'] = f.errors return data
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 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)
def register(): if request.method == 'POST': username = request.form.get('username') # request是从页面获取的,表单一点提交就会提交信息 password = request.form.get('password') repassword = request.form.get('repassword') phone = request.form.get('phone') if password == repassword: # 如果密码一致 # 1注册用户,与模型结合 user = User() # 2给对象的属性赋值 user.username = username # .username表示访问user的属性,获取属性 user.password = generate_password_hash( password) # 使用自带的函数实现加密generate_password_hash user.phone = phone # 属性赋值 # 添加并提交 # 3.将user对象添加到session中(类似缓存) db.session.add(user) # 4.提交到数据库 db.session.commit() return render_template('base.html') 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(): if request.method == 'POST': username = request.form.get('username') password = request.form.get('password') repassword = request.form.get('repassword') phone = request.form.get('phone') if password == repassword: #与模型结合,拿取属性的值 #1.找到模型类并创建对象 user = User() #2.给对象的属性赋值 user.username = username user.password = hashlib.md5(password.encode('utf-8')).hexdigest() user.phone = phone #添加数据至数据库 #3.将user对象添加到session()中【缓存】 db.session.add(user) #4.将缓存的数据插入到数据库里,提交数据 db.session.commit() return redirect(url_for('user.user_center')) 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') if password == repassword: # 与模型结合,完成数据库的添加 # 1. 找到模型类,并创建对象 user = User() # 2. 给对象的属性赋值 user.username = username user.password = password user.phone = phone # 添加进数据库 # 3. 将user对象添加到session中(类似缓存) db.session.add(user) # 4. 提交到数据库 db.session.commit() return '用户注册成功!' 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') if password == repassword: # 与模型结合 # 1.找到模型类并创建对象 user = User() # 2. 给对象赋值 user.username = username user.password = password user.phone = phone # 添加到数据库 # 3.将user对象添加到session中(类似缓存) db.session.add(user) # 4.提交数据部分 db.session.commit() return '用户添加成功' else: return '两次密码不一致' return render_template('user/register.html')
def register(): if request.method == "POST": username = request.form['username'] password = request.form['password'] # users.append( # {'username': username, 'password': password} # ) # 1使用模型类并创建对象 user = User() # 2 给对象赋值 user.username = username user.password = password # 3添加数据 db.session.add(user) # 4 提交 db.session.commit() return "注册成功" # return redirect(url_for('user.index')) return render_template('user/register.html')