示例#1
0
def register():
    if request.method == "GET":
        return render_template('register.html')
    else:
        username = request.form.get('username')
        password = request.form.get('password')
        password2 = request.form.get('password2')
        tel = request.form.get('tel')
        birthday = request.form.get('birthday')
        gender = request.form.get('gender')
        now = datetime.datetime.now()
        avatar = request.files.get('avatar')

        try:
            Users.query.filter_by(username=username).one()
            return render_template('register.html', error=2)
        except NoResultFound:
            if not password or password != password2:
                return render_template('register.html', error=1)
            else:
                u1 = Users(username=username,
                           password=make_password(password),
                           tel=tel,
                           birthday=birthday,
                           gender=gender,
                           created=now)

                if avatar:
                    u1.avatar = save_avatar(avatar)

                db.session.add(u1)
                db.session.commit()

            return redirect('/user/login')
示例#2
0
 def create(self, validated_data):
     u = Users(
         first_name=validated_data['first_name'],
         last_name=validated_data['last_name'],
         # birthday = validated_data['birthday'],
         # number_of_friends = validated_data['number_of_frineds']
     )
     u.save()
     return u
示例#3
0
def register(request):
    user_name = request.GET['user_name']
    password = request.GET['password']
    try:
        user = Users(user_name=user_name, password=password)
        user.save()
        status = 200  # 返回注册成功的编号
    except:
        status = 100  # 返回注册失败的编号
    return HttpResponse(json.dumps({'status': status}))
def join(request):
    user = Users()
    user.name = request.POST['name']
    user.email = request.POST['email']
    user.password = request.POST['password']
    user.gender = request.POST['gender']
    user.save()

    return HttpResponseRedirect('/user/joinsuccess')
示例#5
0
def register(request):
    if request.method == "POST":
        form = SignUpForm(request.POST)
        if form.is_valid():
            user = form.save()
            username = form.cleaned_data.get('username')
            login(request, user)
            current_user = request.user
            profile = Users(user_id=current_user.id,
                            bio=form.cleaned_data.get('Bio'))
            profile.save()
            messages.info(request,
                          "You are now logged in as {}".format(username))
            return HttpResponseRedirect('/home')
        else:
            for msg in form.error_messages:
                messages.error(request, "{msg}: {form.error_messages[msg]}")
    else:
        form = SignUpForm()
    return (render(request, "register.html", context={"form": form}))
示例#6
0
def resgister(request):
    if request.method=="GET":
        return render(request,'users/register.html', {'errmsg': ''})

    if request.method=="POST":
        username = request.POST.get('user_name')
        password = request.POST.get('pwd')
        cpassword = request.POST.get('cpwd')
        email = request.POST.get('email')
        if not all([username, password, email]):
            # 有数据为空
            return render(request, 'users/register.html', {'errmsg': '参数不能为空!'})

        if not re.match(r'^[a-z0-9][\w\.\-]*@[a-z0-9\-]+(\.[a-z]{2,5}){1,2}$', email):
            # 邮箱不合法
            return render(request, 'users/register.html', {'errmsg': '邮箱不合法!'})
        if password!=cpassword:
            return render(request, 'users/register.html', {'errmsg': '两次密码不一致!'})
        try:
            new_data = Users.objects.order_by('-id')[:1]
            if len(new_data)>=1:
                newuid=new_data[0].userid+1
                passport = Users(username=username, password=password, email=email,userid=newuid)
            else:
                passport = Users(username=username, password=password, email=email)
            passport.save()
        except Exception as e:
            print("e: ", e)  # 把异常打印出来
            return render(request, 'users/register.html', {'errmsg': '用户名已存在!'})
        return render(request, 'users/login.html')
示例#7
0
def write(request):
    # 로그인 체크
    if logincheck(request) is False:
        return render(request, 'board/list.html')

    board = Board()
    board.title = request.POST['title']
    board.content = request.POST['content']
    value = Board.objects.aggregate(max_groupno=Max('groupno'))
    board.groupno = 1 if value['max_groupno'] is None else value['max_groupno']+1
    board.orderno = 1
    board.depth = 0
    board.user = Users(request.session['authuser']['id'])


    board.save()

    id = Board.objects.aggregate(max_id=Max('id'))

    return HttpResponseRedirect('/board/view/'+str(id['max_id']))
示例#8
0
 def create(self, data):
     # hash_password = hashlib.md5(data['password'].encode()).hexdigest()
     # changed_data['password'] = hash_password
     # changed_data = data
     # del changed_data['groups']
     # del changed_data['user_permissions']
     u = Users(
         first_name=data['first_name'],
         last_name=data['last_name'],
         username=data['username'],
         password=data['password'],
         email=data['email'],
     )
     u.set_password(data['password'])
     u.save()
     return u
示例#9
0
 def post(self, request):  # 注册页面视图
     # 接收参数
     data = request.POST
     # 表单验证合法
     form = RegisterModelForm(data)
     if form.is_valid():
         # 操作数据库
         clened_data = form.cleaned_data
         # 创建一个用户
         user = Users()
         user.phone = clened_data.get('phone')
         user.password = set_password(clened_data.get('password'))
         user.save()
         return redirect('user:登录')
     # 错误
     else:
         return render(request, 'user/reg.html', context={'form': form})
示例#10
0
 def post(self, request):
     # 完成用户信息的注册
     # 接收参数
     data = request.POST
     # 验证参数合法性 表单验证
     form = RegisterModelForm(data)
     if form.is_valid():
         # 获取清洗后的数据
         cleaned_data = form.cleaned_data
         # 保存数据库
         user = Users()
         user.phone = cleaned_data.get('phone')
         user.password = set_password(cleaned_data.get('password'))
         user.save()
         return redirect('user:登录')
     else:
         return render(request, 'user/reg.html', context={'form': form})
示例#11
0
def reply(request):

    if logincheck(request) is False:
        return HttpResponseRedirect('/user/loginform')

    groupno = int(request.POST['groupno'])
    orderno = int(request.POST['orderno'])
    depth = int(request.POST['depth'])
    # 기존 order update
    Board.objects.filter(groupno=groupno).filter(orderno__gte=orderno).update(orderno=F('orderno')+1)
#     답글 등록
    board = Board()
    board.title = request.POST['title']
    board.content = request.POST['content']
    board.groupno = groupno
    board.orderno = orderno
    board.depth = depth
    board.user = Users(request.session['authuser']['id'])

    board.save()

    id = Board.objects.aggregate(max_id=Max('id'))

    return HttpResponseRedirect('/board/view/'+str(id['max_id']));
示例#12
0
    def post(self, request: HttpRequest):
        try:
            request_json = json.loads(request.body.decode('UTF-8'))
        except json.JSONDecodeError:
            return JSONResponse.new(
                code=400,
                message='request decode error, bad data sent to the server')

        # these are required keys
        _user_name = request_json.get('username')
        _first_name = request_json.get('firstname')
        _last_name = request_json.get('lastname')
        _password = request_json.get('password')

        try:
            self._check_required_inputs(
                [_user_name, _first_name, _last_name, _password])
        except ValueError as err:
            return JSONResponse.new(code=400, message='{}'.format(err.args[0]))

        try:
            Users.objects.get(user_name__exact=_user_name)
        except ObjectDoesNotExist:
            # GOOD, lets create a new user
            new_user = Users()
            salt = token_hex(16)
            signer = Signer(salt=salt)

            new_user.user_id = uuid4().time_mid
            new_user.first_name = _first_name
            new_user.last_name = _last_name
            new_user.user_name = _user_name
            new_user.salt_hash = salt
            new_user.password_hash = signer.signature(_password)
            new_user.email = request_json.get(
                'email', '{}@noemail.set'.format(_user_name))
            new_user.about = request_json.get('about', '')
            new_user.last_login_date = timezone.now()
            new_user.is_active = True

            if request_json.get('profilepic') is not None:
                aws = AWS('snap-life')
                key_name = '{}.png'.format(request_json.get('profilepic'))
                url = aws.upload_profile_image(new_user.user_name, key_name)

                new_user.profile_url = url
            else:
                new_user.profile_url = 'static/assets/usericon.png'

            try:
                new_user.save()
                request.session['{}'.format(new_user.user_id)] = True
            except IntegrityError as err:
                # if this is because we have a collision with our random numbers
                # hash, userID etc. re-create them
                del request.session['{}'.format(new_user.user_id)]
                return JSONResponse.new(
                    code=500, message='username and email need to be unique')

        else:
            return JSONResponse.new(
                code=400,
                message='username {} is already taken'.format(_user_name))

        return JSONResponse.new(code=200,
                                message='success',
                                userid=new_user.user_id)
示例#13
0
def signup():
    return Users().signup()
示例#14
0
def signout():
    return Users().signout()
示例#15
0
    def _create_user(self, username: str, password: str):
        salt = 'blahfffffj349feiblah123'
        signer = Signer(salt=salt)

        user = Users()
        user.user_id = 324
        user.first_name = 'Billy'
        user.last_name = 'Bobtest'
        user.user_name = username
        user.about = "This is about me and the things I like"
        user.last_login_date = timezone.now()
        user.password_hash = signer.signature(password)
        user.salt_hash = salt
        user.save()

        return user
示例#16
0
    def setUpClass(cls):
        super().setUpClass()
        salt = 'blahfffffj349feiblah123'
        signer = Signer(salt=salt)

        user = Users()
        user.user_id = 324
        user.first_name = 'Billy'
        user.last_name = 'Bobtest'
        user.user_name = 'myUsername'
        user.last_login_date = timezone.now()
        user.password_hash = signer.signature('password123')
        user.salt_hash = salt
        user.save()

        cls.user = user
        cls.client = Client()
示例#17
0
    def _create_user(self, username: str, password: str, userid: int):
        salt = 'blahfffff{}j349'.format(password)
        signer = Signer(salt=salt)

        user = Users()
        user.user_id = userid
        user.first_name = 'Billy'
        user.last_name = 'Bobtest'
        user.user_name = username
        user.email = '{}@gmail.com'.format(username)
        user.about = "This is about me and the things I like"
        user.last_login_date = timezone.now()
        user.password_hash = signer.signature(password)
        user.salt_hash = salt
        user.save()

        return user
示例#18
0
def login():
    return Users().login()
示例#19
0
文件: views.py 项目: sjkcdpc/devops-4
def user_manage(request, aid=None, action=None):
    if request.user.has_perms(['asset.view_user', 'asset.edit_user']):
        page_name = ''
        if aid:
            user = get_object_or_404(Users, pk=aid)
            if action == 'edit':
                page_name = '编辑用户'
            elif action == 'delete':
                if user == request.user:
                    Message.objects.create(type=u'用户管理',
                                           user=request.user,
                                           action=u'删除用户',
                                           action_ip=UserIP(request),
                                           content=u'不能删除当前登录用户')
                else:
                    user.delete()
                    Message.objects.create(
                        type=u'用户管理',
                        user=request.user,
                        action=u'删除用户',
                        action_ip=UserIP(request),
                        content=u'删除用户 %s%s,用户名 %s' %
                        (user.last_name, user.first_name, user.username))
                return redirect('user_list')
            elif action == 'view':
                user_detail = Users.objects.filter(id=aid)
                return render(request, 'user/user_profile.html',
                              {'user_detail': user_detail})

        else:
            user = Users()
            action = 'add'
            page_name = '新增用户'

        if request.method == 'POST':
            form = UserForm(request.POST, instance=user)
            if form.is_valid():
                password1 = request.POST.get('password1')
                password2 = request.POST.get('password2')
                perm_select = request.POST.getlist('perm_sel')
                perm_delete = request.POST.getlist('perm_del')
                if action == 'add' or action == 'edit':
                    form.save()
                    if password1 and password1 == password2:
                        user.set_password(password1)
                    user.save()
                    # 授予用户权限
                    user.user_permissions.add(*perm_select)
                    user.user_permissions.remove(*perm_delete)
                    Message.objects.create(type=u'用户管理',
                                           user=request.user,
                                           action=page_name,
                                           action_ip=UserIP(request),
                                           content=u'%s %s%s,用户名 %s' %
                                           (page_name, user.last_name,
                                            user.first_name, user.username))
                    return redirect('user_list')
        else:
            form = UserForm(instance=user)
        data = {
            'form': form,
            'page_name': page_name,
            'action': action,
            'aid': aid
        }

        return render(request, 'user/user_manage.html', data)
    else:
        raise Http404
示例#20
0
def index(request):
    user = Users(u_name="zc")    # 读者
    user.save()
    author = Authors(name="施耐庵")     # 作者
    author.save()
    return HttpResponse("success")