示例#1
0
def auth_registration():
    data = request.get_json()
    username = data.get('username')
    first_name = data.get('first_name')
    last_name = data.get('last_name')
    email = data.get('email')
    pass1 = data.get('password1')
    pass2 = data.get('password2')

    no_exist = User.query.filter_by(email=email).first() is None
    pass_equiv = pass1 == pass2

    xhr = MakeResponse()

    if not pass_equiv:
        xhr.set_error(422, "Paswords do not match.")
    elif not no_exist:
        xhr.set_error(409, "Email address is not available for use.")
    else:
        user = User({
            "username": username,
            "first_name": first_name,
            "last_name": last_name,
            "email": email,
            "password": pass1
        })
        user.save()
        xhr.set_status(200)

    return xhr.response
示例#2
0
def auth_registration():
    data = request.get_json()
    username = data.get('username')
    first_name = data.get('first_name')
    last_name = data.get('last_name')
    email = data.get('email')
    pass1 = data.get('password1')
    pass2 = data.get('password2')

    no_exist = User.query.filter_by(email=email).first() is None
    pass_equiv = pass1 == pass2

    xhr = MakeResponse()

    if not pass_equiv:
        xhr.set_error(422, "Paswords do not match.")
    elif not no_exist:
        xhr.set_error(409, "Email address is not available for use.")
    else:
        user = User({
            "username": username,
            "first_name": first_name,
            "last_name": last_name,
            "email": email,
            "password": pass1
        })
        user.save()
        xhr.set_status(200)

    return xhr.response
示例#3
0
 def test_get_user_tags_not_owner(self):
     user = User(username='******', password='******', email='*****@*****.**')
     user.save()
     get = self.client.get(
         '/users/%s/tags' % user.id,
         headers=self.headers
     )
     self.assertStatus(get, 401)
示例#4
0
 def post(self):
     try:
         body = request.get_json()
         user = User(**body)
         user.hash_password()
         user.save()
         id = user.id
         return {'id': str(id)}, 200
     except FieldDoesNotExist:
         raise SchemaValidationError
     except NotUniqueError:
         raise EmailAlreadyExistsError
     except Exception as e:
         raise InternalServerError
示例#5
0
def create_user(data: dict):
    user = User()
    user.login = data.get("login")
    user.password = data.get("password")
    try:
        with db.atomic() as transaction:
            try:
                user.save()
            except peewee.InternalError:
                transaction.rollback()
            else:
                transaction.commit()
    except peewee.IntegrityError:
        print(f"{data.get('login')}: Already exist.")
    return user.id
示例#6
0
def saveModel(name, email1, pincode, password, number, city, address, state):
    if name != None:
        try:
            a = User.objects.get(email=email1)
            dict.update({print: "User exits already try different email"})
        except User.DoesNotExist:
            pro1 = User(name=name,
                        email=email1,
                        pincode=pincode,
                        password=password,
                        number=number,
                        city=city,
                        address=address,
                        state=state)
            pro1.save()
            return True
示例#7
0
def store(request):

    # if form.is_valid():
    if request.POST:
        role = request.POST.get('role')
        if role == 'p':
            form1 = Publisher()
        elif role == 'a':
            form1 = Advertiser()

        form1.name = request.POST.get('name')
        form1.contact = request.POST.get('contact_number')
        form1.email = request.POST.get('email')
        form1.avatar = request.FILES['image']

        form1.company_name = request.POST.get('company_name')
        form1.company_address = request.POST.get('company_address')
        form1.state = request.POST.get('state')
        form1.city = request.POST.get('city')
        created_at = datetime.datetime.now()
        form1.save()

        if role == 'p':
            record = Publisher.objects.all().order_by('-id')[0]
        elif role == 'a':
            record = Advertiser.objects.all().order_by('-id')[0]

        form_user = User()
        form_user.username = request.POST.get('username')
        form_user.password = request.POST.get('password')
        created_at = datetime.datetime.now()
        form_user.role = request.POST.get('role')
        form_user.uid = form1.id
        form_user.save()
        # instance = form.save(commit=False)
        # instance.save()
        # form = ImageUploadForm(request.POST, request.FILES)
        # if form.is_valid():
        #     if role == 'p':
        #         m = Publisher()
        #     elif role == 'a':
        #         m = Advertiser()
        #
        #     m.avatar = form.cleaned_data['image']
        #     m.save()

    return render(request, 'navigation.html')
示例#8
0
def create_user(data):
    user = User()
    user.login = data.get("login")
    user.password = data.get("password")
    try:
        # атомик - если все транзакции успешные,
        # тогда сохр, а если нет, то ничего не сохр
        with db.atomic() as transaction:
            try:
                user.save()
            except peewee.InternalError as e:
                transaction.rollback()
                print(e)
                print("ERROR")
            else:
                transaction.commit()
                print("COMMIT")
    except peewee.IntegrityError:
        print(f"{data.get('login')}: Already exist.")
    return user.id
示例#9
0
 def test_get_user_tags_not_owner(self):
     user = User(username='******', password='******', email='*****@*****.**')
     user.save()
     get = self.client.get('/users/%s/tags' % user.id, headers=self.headers)
     self.assertStatus(get, 401)