예제 #1
0
def register(req):
    """
    注册
    """
    print("############")
    is_verified = req.session.get("verified")
    if req.method == 'POST' and is_verified:
        urf = UserRegisterForm(req.POST)
        if urf.is_valid():
            try:
                user = User(
                    username=urf.cleaned_data['username'],
                    first_name=urf.cleaned_data['first_name'],
                    last_name=urf.cleaned_data['last_name'],
                    email=urf.cleaned_data['email'],
                    phone=urf.cleaned_data['phone'],
                    mac=urf.cleaned_data['mac'],
                    is_teacher=urf.cleaned_data['is_teacher'],
                )
                user.set_password(urf.cleaned_data['password'])
                user.save()
                return HttpResponse("User {0} Register success".format(
                    user.username))
            except IntegrityError as e:
                return HttpResponse("IntegrityError error: {0}".format(e))
        else:
            # TODO
            return HttpResponse(str(urf.cleaned_data))
    return HttpResponse(status=403)
예제 #2
0
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'
예제 #3
0
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'
예제 #4
0
    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')
예제 #5
0
파일: api.py 프로젝트: 0x90E/PyWDI
    def post(self):
        try:
            username = request.form['username']
            email = request.form['email']
            password = request.form['password']
            user = User(username, email)
            user.set_password(password)
            user.add(user)
            if user.id:
                return_user_info = {
                    'id': user.id,
                    'username': user.username,
                    'email': user.email
                }
                return jsonify(return_success_http_json_result(return_user_info, 'Register success'))
            else:
                return jsonify(return_fail_http_json_result('', 'Register failed'))

        except IntegrityError:
            return jsonify(return_fail_http_json_result('', 'username or email has been registered'))
예제 #6
0
 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
예제 #7
0
    def save(self):
        user = User(username=self.validated_data['username'])
        user.set_password(self.validated_data['password'])
        user.save()

        return user
예제 #8
0
 def create(self, validated_data):
     password = validated_data.pop("password")
     user = User(**validated_data)
     user.set_password(password)
     user.save()
     return user
예제 #9
0
    def save(self):
        user = User(email=self.validated_data['email'])
        user.set_password(self.validated_data['password'])
        user.save()

        return user