コード例 #1
0
def login():
    '''
    func of login user chech authentificated user, pass and empty textbox, and check remember checkbox
    '''
    titleVar = _('Авторизация')
    flash_uncheck = _('Неправильный логин или пароль!')
    flash_check = _('Вы вошли на сайт')

    if current_user.is_authenticated:
        return redirect(url_for('main.index'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user is None or not user.check_password(
                form.password.data
        ) or user.password_hash is None or user.password_hash == "":
            #print("Неправильный логин или пароль")
            flash(flash_uncheck)
            return redirect(url_for('user.login'))
        login_user(user, remember=form.remember_me.data)
        flash(flash_check)
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != '':
            #print("Нет некста")
            next_page = url_for('welcome.index')
        return redirect(next_page)
        #print("Загрузил страницу")
    return render_template('user/login.html', title=titleVar, form_login=form)
コード例 #2
0
ファイル: routes.py プロジェクト: itsDrac/igclone
def login():
    if current_user.is_authenticated:
        return 'you need to logout to access this page'
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first_or_404()
        if user and user.check_password(form.password.data):
            login_user(user, remember=True)
            return redirect(url_for('main.home'))
    return render_template('login.html', form=form)
コード例 #3
0
def index():
    if g.user is not None and g.user.is_authenticated:
        return redirect(url_for('institution'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        login_user(user, remember=form.remember_me.data)
        return redirect(request.args.get('next') or url_for('institution'))
    flash("Nom d\'utilisateur ou mot de passe érroné")
    return render_template('index.html', title='Connexion', form=form)
コード例 #4
0
ファイル: views.py プロジェクト: dogukantufekci/thankspress
def settings_user_deactivate():
    form = LoginForm()
    if form.validate_on_submit():
        form.user.make_deactivated()
        db.session.add(form.user)
        db.session.commit()
        return logout()
    return render_template('users/settings_user_deactivate.html',
        form = form,
        title = 'Deactivate Account')
コード例 #5
0
ファイル: views.py プロジェクト: kiramipt/level_checker
def login():
    if g.user is not None and g.user.is_authenticated():
        return redirect(url_for('index'))
    form = LoginForm()
    if form.validate_on_submit():
        # login and validate the user...
        user = User.query.filter_by(email=form.email.data).first()
        login_user(user)
        flash('Logged in successfully.', category='success')
        return redirect(request.args.get('next') or url_for('index'))
    return render_template('user/login.html', form=form)
コード例 #6
0
def process_login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.objects.get(username=form.username.data)
        if user and user.check_password(form.password.data):
            login_user(user)
            flash('You are logged in')
            return redirect(url_for('posts.index'))
        else:
            flash('Wrong username or password')
            return redirect(get_redirect_target())  #url_for('posts.index'))
コード例 #7
0
def signin():
    form = LoginForm(request.form)
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and user.verify(form.password.data):
            session['nick'] = user.username
            session['email'] = user.email
            flash('Welcome %s' % user.username)
            return redirect(url_for('dashboard'))
        flash('Wrong email or password', 'error-message')
    return render_template('/user/signin.html', form=form)
コード例 #8
0
ファイル: auth.py プロジェクト: amanrao23/task-scheduler
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if not user or not bcrypt.check_password_hash(user.password,
                                                      form.password.data):
            flash('Please check your login details and try again.')
            return redirect(url_for('auth.login'))
        login_user(user, remember=form.remember)
        return redirect(url_for('auth.profile'))

    return render_template('login.html', form=form)
コード例 #9
0
ファイル: views.py プロジェクト: mastrayer/CSM
def login():
	form = LoginForm(request.form)

	if form.validate_on_submit():
		user = User.query.filter_by(email=form.email.data).first()

		if user and check_password_hash(user.password, form.password.data):
			session['user_id'] = user.id
			flash('Welcome %s' % user.nickname)
			return redirect(url_for('general.main'))
		flash('Worng email or password', 'error-message')
	return redirect(url_for('general.main')) 
コード例 #10
0
def login():
    form = LoginForm()

    if form.validate_on_submit():
        user = User.find_by(email=form.email.data)

        if not user or not user.login(form.password.data, form.remember.data):
            flash('Email or password incorrect.', 'danger')
            return render_template('user_login.html', title='Login', form=form)

        return redirect(
            request.args.get('next') or url_for('accounts.pagination'))

    return render_template('user_login.html', title='Login', form=form)
コード例 #11
0
ファイル: views.py プロジェクト: dogukantufekci/thankspress
def login():
    if g.user.is_authenticated():
        flash("You are already registered.")
        return redirect(url_for('user_thanks', username = g.user.username))
    form = LoginForm()
    if form.validate_on_submit():
            login_user(form.user, remember = form.remember_me.data)
            g.user.date_last_logged_in = datetime.utcnow()
            db.session.add(g.user)
            db.session.commit()
            return redirect(request.args.get("next") or url_for('thanks'))
    return render_template('users/login.html',
        form = form,
        title = 'Login')
コード例 #12
0
def login():
    data = request.get_json(force=True)
    form = LoginForm(MultiDict(mapping=data))
    if form.validate():
        username = data.get('username').lower()
        password = data.get('password')
        user = User.query.filter_by(username=username).first()
        if not user or not user.verify_password(password):
            return jsonify({
                "form_errors":
                "Nom d\'utilisateur ou mot de passe incorrect"
            }), 400
        return jsonify(user.to_json())
    return jsonify({"form_errors": form.errors}), 400
コード例 #13
0
def login():
    form = LoginForm(request.form)
    if form.validate_on_submit():
        user = User.query.filter(
            db.or_(User.username == form.username.data,
                   User.email == form.username.data)).first()
        if user is not None and user.check_password(form.password.data):
            login_user(user)
            flash('You are logged in. Welcome!', 'success')
            return redirect(url_for('main.home'))
        else:
            flash('Wrong username/email or password.', 'danger')
            return render_template('user/login.html', form=form)
    return render_template('user/login.html', form=form)
コード例 #14
0
def login():
    if current_user.is_authenticated:
        return make_response(redirect("/"))

    form = LoginForm()
    if form.validate_on_submit():
        #try:
        try:
            controller.login(form.username.data, form.password.data)
            return redirect(url_for('web.index'))
        except UserDoesNotExistError:
            flash("Invalid username or password.")
        #except:
        #	return redirect(url_for('user.login'))
    return render_template("login.html", form=form)
コード例 #15
0
    def login(self):
        form = LoginForm()
        service = UserService()

        if request.method == 'POST' and form.validate_on_submit():
            user = service.login(form.username.data, form.password.data)
            if user:
                flash('Login Successfully.', 'success')
                login_user(user, form.remember.data)
                next_path = request.args.get('next', request.path)
                return redirect(next_path)
            else:
                raise Exception('Username or Password Incorrect.')

        return render_template('user/login.html', form=form)
コード例 #16
0
ファイル: views.py プロジェクト: Ottermad/SocialNetwork
def login():
    form = LoginForm()

    if form.validate_on_submit():
        try:
            user = User.get(User.email == form.email.data)
        except DoesNotExist:
            flash("Your email or password does not exist.")
        else:
            if check_password_hash(user.password, form.password.data):
                login_user(user)
                flash("You have been logged in.")
                return redirect(url_for(".index"))
            else:
                flash("Your email or password does not exist.")
    return render_template("login.html", form=form)
コード例 #17
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(username=form.username.data).first()
        if user and bcrypt.check_password_hash(user.password, form.password.data):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')
            if next_page:
                return redirect(next_page)
            else:
                return redirect(url_for('main.home'))
        else:
            flash('登录失败,请检查账号或者密码', 'danger')
    return render_template('user/login.html', title='登录', form=form)
コード例 #18
0
ファイル: routes.py プロジェクト: Allint29/Nail
def index():
    form_login = LoginForm()
    #блок добавления фотографий галереи сначала подгружаю только 10 картинок и осылаю ориентиры начала списка и конец
    list_gallary = MyWork.query.filter_by(show=1).order_by(
        MyWork.published).all()
    list_id_gallary = ','
    list_id_gallary = list_id_gallary.join([str(w.id) for w in list_gallary])
    list_with_z_index = []
    z = 100
    display = 'none'
    for work in list_gallary[-2:]:
        z = z + 1
        if z - 100 == len(list_gallary[-2:]):
            display = 'block'
        list_with_z_index.append({'work': work, 'z': z, 'display': display})
    ################################################################################

    #блок добавления новостей сайта
    list_news = MasterNews.query.order_by(MasterNews.published.desc())[0:3]
    count_list_news = len(list_news)
    #################################################################################



    return render_template("welcome/index.html", form_login=form_login, \
        list_gallary = list_gallary, list_with_z_index = list_with_z_index, \
        list_news=list_news, count_list_news=count_list_news, \
        list_id_gallary=list_id_gallary)
コード例 #19
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('posts.index'))
    form = LoginForm()
    if form.validate_on_submit():
        # user = User.query.filter_by(username=form.username.data).first()
        user = User.query.filter_by(email=form.email.data).first_or_404()
        if user is None or not user.check_password(form.password.data):
            flash('Invalid username or password')
            return redirect(url_for('posts.login'))
        login_user(user, remember=form.remember_me.data)
        next_page = request.args.get('next')
        if not next_page or url_parse(next_page).netloc != '':
            next_page = url_for('posts.index')
        return redirect(next_page)
    return render_template('user/login.html', title='Sign In', form=form)
コード例 #20
0
ファイル: views.py プロジェクト: m85091081/arcane
def login(request, id=None):
    if request.user.is_authenticated():
        return redirect('home')
    else:
        if not User.objects.filter(username=id).exists():
            return render(request,
                          "submit.html", {
                              "success": False,
                              "content": "不認識的使用者,你真的是勇者嗎?",
                              "title": "發現不明人士"
                          },
                          status=404)

    if not request.POST:
        form = LoginForm()
        return render(request, "user/login.html", locals())
    else:
        username = id
        password = request.POST.get("password", '')
        user = authenticate(username=username, password=password)
        if user is not None:
            if user.is_active:
                auth_login(request, user)
                return redirect('home')
            else:
                error = "奇怪的錯誤"
                return render(request, "user/login.html", locals())
        else:
            error = "錯誤的PIN碼"
            return render(request, "user/login.html", locals())
コード例 #21
0
def index():
    news_list = News.query.filter(
        News.text.isnot(None)
    ).filter(News.text != "").filter(News.show == 1).order_by(
        News.published.desc()
    )  #.all() #filter(News.text.isnot("")).all() # #.filter(News.show==1).order_by(News.published.desc()) #.all()
    # work_list = MyWork.query.order_by(MyWork.published.desc()).all()
    form_login = LoginForm()
    page = request.args.get('page')
    if page and page.isdigit():
        page = int(page)
    else:
        page = 1

    #last_pict = random.randint(5, len(work_list))
    #work_list = work_list[last_pict-5 : last_pict]

    pages_new = news_list.paginate(page=page, per_page=3)

    next_url = url_for('news.index',
                       page=pages_new.next_num) if pages_new.has_next else None
    prev_url = url_for('news.index',
                       page=pages_new.prev_num) if pages_new.has_prev else None

    return render_template("news/index.html",
                           pages=pages_new,
                           next_url=next_url,
                           prev_url=prev_url,
                           form_login=form_login)
コード例 #22
0
def book(book_isbn):
    form_list = Add_Readinglist()
    form_login = LoginForm()
    form_register = RegisterForm()
    book = Book.query.get_or_404(book_isbn)
    if current_user.is_authenticated:
        form = Add_book_to_readinglit()
        selected_list = form.lists.data
        if request.method == 'POST':
            book.books.append(selected_list)
            db.session.commit()
            flash('New Book has been added to list!', 'success')
            return redirect(url_for('main.index'))
        return render_template('book/book.html',
                               title=book.title,
                               book=book,
                               form=form,
                               form_list=form_list,
                               form_login=form_login,
                               form_register=form_register)
    return render_template('book/book.html',
                           form_list=form_list,
                           title=book.title,
                           book=book,
                           form_login=form_login,
                           form_register=form_register)
コード例 #23
0
def articlepage(request, article_id):
    article = Article.objects.get(id=article_id)
    content_type = ContentType.objects.get_for_model(Article)
    article.record_num()

    try:
        last_article = Article.objects.filter(id__lt=article_id).last()
    except:
        last_article = None

    try:
        next_article = Article.objects.filter(id__gt=article_id).first()
    except:
        next_article = None

    message = {}
    message['article'] = article
    message['last_article'] = last_article
    message['next_article'] = next_article
    message['login_form'] = LoginForm()

    message['comments'] = Comment.objects.filter(
        content_type=content_type, object_id=article_id,
        parent_comment=None).order_by('-comment_time')
    message['comment_form'] = CommentForm(initial={
        'content_type': 'article',
        'object_id': article_id,
        'reply_id': '0'
    })

    message['article_like'] = 1
    return render(request, 'article/articlepage.html', message)
コード例 #24
0
def add_book():
    form = Add_Book()
    form_login = LoginForm()
    form_register = RegisterForm()
    form_cat = Add_Category()
    form_publisher = Add_Publisher()
    form_author = Add_Author()
    author = form.author.data
    publisher = form.publisher.data
    category = form.category.data
    if form.validate_on_submit():
        book = Book(title=form.title.data,
                    year=form.year.data,
                    book_cover=form.book_cover.data,
                    description=form.description.data,
                    publisher_id=publisher.PublisherId,
                    category_id=category.CategoryId,
                    author_id=author.AuthorId)
        db.session.add(book)
        db.session.commit()
        flash('New Book has been added!', 'success')
        return redirect(url_for('main.index'))
    return render_template('book/add_book.html',
                           title='New Book',
                           form=form,
                           legend='Add Book',
                           form_login=form_login,
                           form_register=form_register,
                           form_cat=form_cat,
                           form_publisher=form_publisher,
                           form_author=form_author)
コード例 #25
0
def login():
    if g.user is not None and g.user.is_authenticated():
        return redirect(url_for('index'))
    form = LoginForm()
    if form.validate_on_submit():
        # login and validate the user...
        user = User.query.filter_by(email=form.email.data).first()
        user.update_login_info(request.environ['REMOTE_ADDR'])
        db.session.add(user)
        db.session.commit()

        login_user(user)
        flash('Logged in successfully !', category='success')

        return redirect(request.args.get('next') or url_for('index'))
    return render_template('user/login.html', form=form)
コード例 #26
0
ファイル: views.py プロジェクト: rfairburn/mwostatter
def login():
    '''
    Login form
    '''
    form = LoginForm(request.form)
    # make sure data are valid, but doesn't validate password is right
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
    # we use werzeug to validate user's password
        if user and check_password_hash(user.password, form.password.data):
            # the session can't be modified as it's signed, 
            # it's a safe place to store the user id
            session['user_id'] = user.id
            flash('Welcome %s' % user.name)
            return redirect(url_for('user.home'))
        flash('Wrong email or password', 'error-message')
    return render_template('user/login.html', form=form)
コード例 #27
0
def login():
    '''
    Login form
    '''
    form = LoginForm(request.form)
    # make sure data are valid, but doesn't validate password is right
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        # we use werzeug to validate user's password
        if user and check_password_hash(user.password, form.password.data):
            # the session can't be modified as it's signed,
            # it's a safe place to store the user id
            session['user_id'] = user.id
            flash('Welcome %s' % user.name)
            return redirect(url_for('user.home'))
        flash('Wrong email or password', 'error-message')
    return render_template('user/login.html', form=form)
コード例 #28
0
def one_list(list_id):
    form_login = LoginForm()
    form_register = RegisterForm()
    reading_list = Lists.query.get_or_404(list_id)
    return render_template('reading_list/reading_list.html',
                           title=reading_list.ListName,
                           reading_list=reading_list,
                           form_login=form_login,
                           form_register=form_register)
コード例 #29
0
def login():
    form = LoginForm()

    if form.validate_on_submit():
        email = form.email.data
        password = form.password.data
        user_email, user_pwd_hash, user_name = load_user(email)
        if user_email is None:
            flash('User not present')
        elif not bcrypt.checkpw(password.encode('utf8'), user_pwd_hash):
            flash('Incorrect Password!')
            return redirect(url_for('user.login'))
        else:
            session['email'] = user_email
            session['name'] = user_name
        return redirect(url_for('index'))

    return render_template('login.html', form=form)
コード例 #30
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('user.account'))

    form = LoginForm()
    if form.validate_on_submit():
        user = users.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.data)
            next_page = request.args.get('next')
            #flash('Login Successful.')
            return redirect(next_page) if next_page else redirect(
                url_for('main.register'))
        else:
            flash('Login Unsuccessful. Please check email and password')
    else:
        print(form.errors)
    return render_template('login.html', title='Login', form=form)
コード例 #31
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for('main.home'))
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user and bcrypt.check_password_hash(user.password,
                                               form.password.data):
            login_user(user, remember=form.remember.data)
            session['user_id'] = user.public_key
            next_page = request.args.get('next')
            flash(f'Hi {user.full_name}')
            if not next_page or url_parse(next_page).netloc != '':
                return redirect(url_for('main.home'))
            else:
                return redirect(next_page)
        flash('Email or password incorrect please try again')
        return redirect(url_for('user.login'))
    return render_template('login.html', form=form)
コード例 #32
0
def index():
    form_login = LoginForm()
    form_register = RegisterForm()
    page = request.args.get('page', 1, type=int)
    books = Book.query.order_by(Book.isbn.desc()).paginate(page=page,
                                                           per_page=6)
    return render_template('index.html',
                           books=books,
                           form_login=form_login,
                           form_register=form_register)
コード例 #33
0
def all_publishers():
    form_publisher = Add_Publisher()
    form_login = LoginForm()
    form_register = RegisterForm()
    publishers = Publisher.query.all()
    return render_template('publisher/publishers.html',
                           form_publisher=form_publisher,
                           publishers=publishers,
                           title='Publishers',
                           form_login=form_login,
                           form_register=form_register)
コード例 #34
0
def all_lists():
    form_list = Add_Readinglist()
    form_login = LoginForm()
    form_register = RegisterForm()
    reading_list = Lists.query.filter_by(UserId=current_user.id).all()
    return render_template('reading_list/reading_lists.html',
                           form_list=form_list,
                           title=current_user.name,
                           reading_list=reading_list,
                           form_login=form_login,
                           form_register=form_register)
コード例 #35
0
def all_author():
    form_author = Add_Author()
    form_login = LoginForm()
    form_register = RegisterForm()
    authors = Author.query.all()
    return render_template('author/authors.html',
                           authors=authors,
                           title='Authors',
                           form_author=form_author,
                           form_login=form_login,
                           form_register=form_register)
コード例 #36
0
def all_categories():
    form_cat = Add_Category()
    form_login = LoginForm()
    form_register = RegisterForm()
    categories = Category.query.all()
    return render_template('category/categories.html',
                           categories=categories,
                           title='Categories',
                           form_cat=form_cat,
                           form_login=form_login,
                           form_register=form_register)