Exemplo n.º 1
0
def user_register(request):
    registered = False
    if request.method == 'POST':
        if request.POST.get('psw') == request.POST.get('psw-repeat'):
            user_name1 = request.POST.get('username')
            pass_word1 = request.POST.get('psw')
            enc_password = make_password(pass_word1)
            user = User(username=user_name1, password=enc_password)
            user.email = request.POST.get('email')
            try:
                user.save()
                user_obj = USER_LOGIN(
                    first_name=request.POST.get('First_Name'),
                    last_name=request.POST.get('Last_Name'),
                    user_name=request.POST.get('username'),
                    pass_word=request.POST.get('psw'),
                    email_id=request.POST.get('email'),
                    gender=request.POST.get('gender'))
                user_obj.save()

                registered = True
                return index(request)
            except:
                return HttpResponse(
                    "sorry username or email already exist please try with other one!"
                )

        else:
            #messages.warning(request, 'Invalid credentials!')
            return HttpResponse("both passwords are not matched!")

    else:
        return render(request, 'testapp/RegisterPage.html')
 def test_cache_query_set(self):
     """Basic cache test: second get comes from cache."""
     self.assertEquals(len(User.objects.all()), 2)
     user = User(name = "test01")
     user.save()
     for x in User.objects.all():
       print x.name
     self.assertEquals(len(User.objects.all()), 3)
Exemplo n.º 3
0
def adduser(request):
    if request.method == "POST":
        name = request.POST.get('U_name')
        pass1 = request.POST.get('U_pass')
        print(name, pass1)
        u = User(U_name=name, U_pass=pass1)
        u.save()
        return HttpResponse("User has been added!")
Exemplo n.º 4
0
 def test_cache_query_set(self):
     """Basic cache test: second get comes from cache."""
     self.assertEquals(len(User.objects.all()), 2)
     user = User(name="test01")
     user.save()
     for x in User.objects.all():
         print x.name
     self.assertEquals(len(User.objects.all()), 3)
def showdata(request):
    if request.method == 'POST':
        # print('ye post method se aa ra hai ')
        # print(request.POST.get('email'))
        # print(request.POST.get('passward'))

        nm = request.POST.get('email')
        pw = request.POST.get('passward')
        reg = User(email=nm, passward=pw)
        reg.save()

    else:
        return render(request, 'testapp/index.html')
    return render(request, 'testapp/index.html')
Exemplo n.º 6
0
def Tourist_registration(request):
    registered=False
    if request.method=="POST":
            first_name = request.POST.get('Firstname')
            print(first_name)
            last_name=request.POST.get('Lastname')
            user_name=request.POST.get('Username')
            email_id=request.POST.get('Email')
            pass_word = request.POST.get('Password')
            language=request.POST.get('language')
            gender=request.POST.get('gender')
            age=request.POST.get('age')
            phone_number=request.POST.get('Phonenumber')
            enc_password=make_password(pass_word)
            user=User(username=user_name,password=enc_password)
            user.is_tourist=True
            user.is_guide=False
            user.email=email_id
            try:
                user.save()
                form=Tourist_Registration(first_name=first_name,last_name=last_name,user_name=user_name,email_id=email_id,pass_word=pass_word,language=language,gender=gender,age=age,phone_number=phone_number)
                t=form.save()
            except:
                messages.warning(request, 'username or Email already exists Please Try again with New one')
                return HttpResponseRedirect('testapp/index.html')

            registered = True
            messages.success(request, 'successfully Registered Please Login!')
            return HttpResponseRedirect('testapp/index.html')
    else:
        return render(request,'testapp/index.html')
Exemplo n.º 7
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Your account has been created! You are now able to log in',
              'success')
        return redirect(url_for('users.login'))
    return render_template('register.html', title='Register', form=form)
Exemplo n.º 8
0
def reset_token(token):
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    user = User.verify_reset_token(token)
    if user is None:
        flash('That is an invalid or expired token', 'warning')
        return redirect(url_for('users.reset_request'))
    form = ResetPassswordForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        user.password = hashed_password
        db.session.commit()
        flash('Your password has been updated! You are now able to log in',
              'success')
        return redirect(url_for('users.login'))
    return render_template('reset_token.html',
                           title='Reset Request',
                           form=form)
Exemplo n.º 9
0
def create_user():
    data = request.get_json(force=True)
    user = User(data['name'], data['email'])
    db_session.add(user)
    db_session.commit()
    return (json.dumps(user.as_dict(), indent=2), 201)