コード例 #1
0
ファイル: routes.py プロジェクト: dongocanh96/class_manager
def register():
    if current_user.is_authenticated:
        return redirect(url_for("index"))
    form = RegistrationForm()
    if form.validate_on_submit():
        if form.access_level.data == "599s1Z]76G4MVMX":
            user = User(access_level=1,
                        username=form.username.data,
                        password=form.password.data,
                        fullname=form.fullname.data,
                        email=form.email.data,
                        phone_number=form.phone.data)
            db.session.add(user)
            db.session.commit()
            flash("Congratulations, you are now a registered teacher!")
        else:
            user = User(access_level=0,
                        username=form.username.data,
                        password=form.password.data,
                        fullname=form.fullname.data,
                        email=form.email.data,
                        phone_number=form.phone.data)
            db.session.add(user)
            db.session.commit()
            flash("Congratulations, you are now a registered student!")
        return redirect(url_for("login"))
    return render_template("register.html", title="Register", form=form)
コード例 #2
0
ファイル: views.py プロジェクト: srprasanna/beehyv_blog
def index(request):
    if request.method=='POST':
        username=request.POST.get('username')
        password=request.POST.get('password')
        user=authenticate(username=username,password=password)
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()  
            return HttpResponseRedirect('/success/')
        if user is not None:
            if user.is_active:
                login(request, user)
                return HttpResponseRedirect('/')
            else:
                return HttpResponse("The password is valid, but the account has been disabled!<a href='/'> Home page</a>")
        else:
            # the authentication system was unable to verify the username and password
            return HttpResponse("Invalid entry<a href='/'> Home page</a>")
        
    else:
        #return render_to_response('login.html', {} , context)
        form = RegistrationForm()
        args={}
        args.update(csrf(request))
        args['form']=RegistrationForm
        args['full_name']=request.user.username
        return render_to_response('home.html',args,context_instance=RequestContext(request))
コード例 #3
0
def register(request):
    context = {}

    # Just display the registration form if this is a GET request.
    if request.method == 'GET':
        context['form'] = RegistrationForm()
        return render(request, 'blog/register.html', context)

    # Creates a bound form from the request POST parameters and makes the
    # form available in the request context dictionary.
    form = RegistrationForm(request.POST)
    context['form'] = form

    # Validates the form.
    if not form.is_valid():
        return render(request, 'blog/register.html', context)

    # At this point, the form data is valid.  Register and login the user.
    new_user = User.objects.create_user(
        username=form.cleaned_data['username'],
        password=form.cleaned_data['password1'],
        email=form.cleaned_data['email'],
        first_name=form.cleaned_data['first_name'],
        last_name=form.cleaned_data['last_name'])
    new_user.save()

    # Logs in the new user and redirects to his/her todo list
    new_user = authenticate(username=form.cleaned_data['username'],
                            password=form.cleaned_data['password1'])
    login(request, new_user)

    user_profile = UserProfile(user=new_user)
    user_profile.save()

    return redirect(reverse('home'))
コード例 #4
0
ファイル: routes.py プロジェクト: MadPele/flaskBlog
def registration():
    form = RegistrationForm()

    if form.validate_on_submit():
        flash(f'Account created for {form.username.data}!', 'success')
        return redirect(url_for('home'))
    return render_template('registration.html',
                           title='Registration',
                           form=form)
コード例 #5
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(firstname=form.firstname.data, surname=form.surname.data, username=form.username.data, email=form.email.data, password=form.password.data)
        db.session.add(user)
        db.session.commit()
        login_user(user)
        flash('Congratulations! You registered an account!')
        return redirect(url_for('home'))
    return render_template('register.html', title='Register', form=form)
コード例 #6
0
ファイル: routes.py プロジェクト: Hadiaj448/Amazon
def register():

    form=RegistrationForm()
    if form.validate_on_submit():
        user=User(username=form.username.data,email=form.email.data,password=form.password.data)
        db.session.add(user)
        db.session.commit()
        flash(f'Account Created Successfully','success')
        return redirect(url_for('index'))
    return render_template('register.html',title='Register',form=form)
コード例 #7
0
ファイル: routes.py プロジェクト: NZaidi29/Flask-blog
def register():
    search = SearchForm()
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(firstname=form.firstname.data, lastname=form.lastname.data, username=form.username.data, email=form.email.data, password=form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Registration successful.')
        return redirect(url_for('home'))
    return render_template('register.html', title='Register', form=form, search=search)
コード例 #8
0
ファイル: views.py プロジェクト: dunopiorg/first-django-blog
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            form.save()
            return redirect('/blog/home')
    else:
        form = RegistrationForm()
        
        args = {'form': form}
        return render(request, 'blog/reg_form.html', args)
コード例 #9
0
ファイル: route.py プロジェクト: ThirupathiThatikanti/blog
def register():
    if current_user.is_authenticated:
        return redirect(url_for('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('congrats!! Your account has been created! Please login to continue',category='success')
        return redirect(url_for('home'))
    return render_template('register.html',title='Register',form=form)
コード例 #10
0
ファイル: routes.py プロジェクト: maxio-yu/MicroBlog_Flask
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data, email=form.email.data)
        user.set_password(form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Congratulations, you are now a registered user!')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
コード例 #11
0
def register(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                username=form.cleaned_data['username'],
                password=form.cleaned_data['password1'],
                email=form.cleaned_data['email'])
            return register_success(request)
    else:
        form = RegistrationForm()
    return render(request, 'blog/register.html', {'form': form})
コード例 #12
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_pw = bcrypt.generate_password_hash(form.password.data).decode('utf-8')
        user = User(username = form.username.data, email = form.email.data, password = hashed_pw)
        db.session.add(user)
        db.session.commit()
        flash('Your Account Has Been Created', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
コード例 #13
0
def register():
    if current_user.is_authenticated:
        return redirect("/")
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        flash(f'you account has been created! you can now log in', 'success')
        return redirect("/")
    return render_template('register.html', form=form)
コード例 #14
0
ファイル: routes.py プロジェクト: MichalLeszczynski/MyWebPage
def register():
    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.username.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("login"))
    return render_template("register.html", title="Register", form=form)
コード例 #15
0
ファイル: routes.py プロジェクト: notgitika/blog-using-flask
def register():
    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(f'Your account has been created. Please log in now', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
コード例 #16
0
ファイル: page_routes.py プロジェクト: theNamskov/flask-blog
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hashed_password = generate_password_hash(form.password.data,
                                                 method='sha256')
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash('Account created successfully!', 'success')
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)
コード例 #17
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=sha256_crypt.encrypt(form.password.data))
        db.session.add(user)
        db.session.commit()
        flash('Account created for ' + form.username.data + '!', 'success')
        return redirect(url_for('login'))

    return render_template("register.html", title='Register', form=form)
コード例 #18
0
ファイル: routes.py プロジェクト: YoussefBayad/blog-flask
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    form = RegistrationForm()
    if form.validate_on_submit():
        flash('Your account has been created! You are now able to log in',
              'success')
        hashed_password = generate_password_hash(form.password.data)
        user = User(username=form.username.data,
                    email=form.email.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        return redirect(url_for('login'))
    return render_template("register.html", title="Register", form=form)
コード例 #19
0
ファイル: views.py プロジェクト: rahulk98/sample-blog
def create_acc(request):
    if request.method == 'POST':
        form = RegistrationForm(request.POST)
        if form.is_valid():
            user = User.objects.create_user(
                first_name=form.cleaned_data['firstname'],
                last_name=form.cleaned_data['lastname'],
                username=form.cleaned_data['username'],
                password=form.cleaned_data['password1'],
                email=form.cleaned_data['email'])
            return HttpResponseRedirect('/accounts/login')
    form = RegistrationForm()
    context = {'form': form}
    template_name = 'registration/create_Acc.html'
    return render(request, template_name, context)
コード例 #20
0
ファイル: routes.py プロジェクト: Throupy/Blog
def register():
    if current_user.is_authenticated:
        return redirect(url_for('index'))
    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!', 'is-success')
        return redirect(url_for('index'))
    return render_template('register.html', form=form)
コード例 #21
0
def register(request):
    context = {}

    # Just display the registration form if this is a GET request.
    if request.method == 'GET':
        context['form'] = RegistrationForm()
        return render(request, 'blog/register.html', context)

    # Creates a bound form from the request POST parameters and makes the
    # form available in the request context dictionary.
    form = RegistrationForm(request.POST)
    context['form'] = form

    # Validates the form.
    if not form.is_valid():
        return render(request, 'blog/register.html', context)

    # At this point, the form data is valid.  Register and login the user.
    new_user = User.objects.create_user(
        username=form.cleaned_data['username'],
        password=form.cleaned_data['password1'],
        email=form.cleaned_data['email'],
        first_name=form.cleaned_data['first_name'],
        last_name=form.cleaned_data['last_name'])

    # Mark the user as inactive to prevent login before email confirmation.
    new_user.is_active = False
    new_user.save()

    # Generate a one-time use token and an email message body
    token = default_token_generator.make_token(new_user)

    email_body = """
Please click the link below to verify your email address and
complete the registration of your account:

  http://{host}{path}
""".format(host=request.get_host(),
           path=reverse('confirm', args=(new_user.username, token)))

    send_mail(subject="Verify your email address",
              message=email_body,
              from_email="*****@*****.**",
              recipient_list=[new_user.email])

    context['email'] = form.cleaned_data['email']

    return render(request, 'blog/needs-confirmation.html', context)
コード例 #22
0
ファイル: route.py プロジェクト: salimep/docker
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form=RegistrationForm()
    print(form.email.errors)

    if form.validate_on_submit():
        user=User(username=form.username.data,email=form.email.data,
                    password=bcrypt.generate_password_hash(form.password.data).decode('utf-8'))
        db.session.add(user)
        db.session.commit()
        flash('Account has created for {}'.format(form.username.data),'success')
        return redirect(url_for('home'))


    return render_template("register.html",title="register",form=form)
コード例 #23
0
ファイル: routes.py プロジェクト: Rakshith176/BLOG
def register():
    if current_user.is_authenticated:
        return redirect(url_for('home'))
    form = RegistrationForm()
    if form.validate_on_submit():
        hash_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        users = User(username=form.username.data,
                     email=form.email.data,
                     password=hash_password)
        db.session.add(users)
        db.session.commit()
        flash(f"{form.username.data} Account is created!! You can now login!!",
              'success')
        return redirect(url_for('login'))
    return render_template('register.html', form=form, title='register')
コード例 #24
0
ファイル: routes.py プロジェクト: krutskiy/Flask_Three
def register():
    if current_user.is_authenticated:
        return redirect(url_for('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('Аккаунт создан! Можете зайти', 'success')
        return redirect(url_for('login'))

    return render_template('register.html', title='Регистрация', form=form)
コード例 #25
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('landing'))
    else:
        form = RegistrationForm()
        if form.validate_on_submit():
            hashed = argon2.generate_password_hash(form.password.data)
            user = User(username=form.username.data,
                        password=hashed,
                        email=form.email.data)
            db.session.add(user)
            db.session.commit()
            flash(f'Account created for {form.username.data}.\
            You can now log in',
                  category='success')
            return redirect(url_for('landing'))
        return render_template('register.html', form=form)
コード例 #26
0
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    firstname=form.firstname.data,
                    lastname=form.lastname.data,
                    email=form.email.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        flash('Registration successful!')
        if request.args.get('next') == '/register' or request.args.get(
                'next') == '/login':
            return redirect(url_for('home'))
        else:
            return redirect(request.args.get('next') or url_for('home'))
    return render_template('register.html', title='Register', form=form)
コード例 #27
0
def registration(request):
    form2 = RegistrationForm()
    if request.method == "POST":
        print 11111
        form2 = RegistrationForm(request.POST)
        print form2.errors
        if form2.is_valid():
            user = User.objects.create_user(username=request.POST['login'],
                                            first_name=request.POST['name'],
                                            last_name=request.POST['surname'],
                                            email=request.POST['sender'],
                                            password=request.POST['password'])
            user.save()
            #            print 1111111111
            #            print User.objects.filter(user=user).exists()
            return render(request, 'chapters.html', locals())
    return render(request, "registration/registration.html", locals())
コード例 #28
0
ファイル: routes.py プロジェクト: uzoma-u/flask-blog
def register():
    form = RegistrationForm()
    if form.validate_on_submit():
        user = User(username=form.username.data,
                    firstname=form.firstname.data,
                    lastname=form.lastname.data,
                    email=form.email.data,
                    password=form.password.data)
        db.session.add(user)
        db.session.commit()
        flash("Successful! Thanks for registering")
        login_user(user)
        return redirect(url_for("home"))

        flash("Registration unsuccessful, kindly check your details")

    return render_template("register.html", title="Register", form=form)
コード例 #29
0
def signup():
    if current_user.is_authenticated:
        return redirect(url_for('home'))

    form = RegistrationForm()
    if form.validate_on_submit():
        print("in the register route")
        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(f"Horray you got an account now: {form.username.data}!",
              "success")
        return redirect(url_for('login'))
    return render_template("register.html", form=form, title="signup")
コード例 #30
0
def register():
    if current_user.is_authenticated:
        return redirect(url_for('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,
                    phone=form.phone.data,
                    password=hashed_password)
        db.session.add(user)
        db.session.commit()
        flash(f'Account created you are now able to log in!', 'success')
        return redirect(url_for('login'))
    elif request.method == 'GET':
        form.phone.data = '+91 '
    return render_template('register.html', title='Register', form=form)
コード例 #31
0
def register(request):
    registered = False

    if(request.method =="POST"):
        user_form = RegistrationForm(data=request.POST)

        if(user_form.is_valid()):
            user = user_form.save()
            user.set_password(user.password)
            user.save()
            registered = True
        else:
            print(user_form.errors)

    else:
        user_form = RegistrationForm

    return render(request,'blog/registration.html',
    {'user_form':user_form,'registered':registered})
コード例 #32
0
def register():
    if current_user.is_authenticated:
        return redirect(
            url_for('home'))  #url_for(name of the function of the route)
    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(
            "Welcome, {}! You are now able to log in".format(
                form.username.data), 'success'
        )  #f string: python 3.6 and above; 'success' is the Bootstrap class
        return redirect(url_for('login'))
    return render_template('register.html', title='Register', form=form)