Ejemplo n.º 1
0
def login():
    app.logger.info( 'g user: '******' is auth: ' +str(  g.user.is_authenticated) )
    if g.user is not None and g.user.is_authenticated:
        return redirect(url_for('index'))
    form = LoginForm()
    if form.validate_on_submit():
        session['remember_me'] = form.remember_me.data
        app.logger.info( 'val_on_submit: ' + str( oid.try_login(form.openid.data, ask_for = ['nickname', 'email'])) )

        return oid.try_login(form.openid.data, ask_for=['nickname', 'email'])
    return render_template('login.html',
                           title='Sign In',
                           form=form,
                           providers=app.config['OPENID_PROVIDERS'])
Ejemplo n.º 2
0
def login():
    """Does the login via OpenID.  Has to call into `oid.try_login`
    to start the OpenID machinery.
    """
    # if we are already logged in, go back to were we came from
    if logged_in_user() is not None:
        return redirect(oid.get_next_url())
    if request.method == 'POST':
        openid = request.form.get('openid')
        if not re.findall('^https*://', openid):
            openid = 'http://' + openid
        if openid:
            pape_req = pape.Request([])
            x = oid.try_login(openid,
                              ask_for=['email', 'nickname'],
                              ask_for_optional=['fullname'],
                              extensions=[pape_req])
            return x
    form = LoginForm()
    if form.validate_on_submit():
        return redirect(oid.get_next_uril())

    msg = oid.fetch_error()
    if msg:
        flash(msg)
    elif fns_util.pu_time():
        flash('Please enter an openid')

    return render_template('login.html',
                           next=oid.get_next_url(),
                           error=oid.fetch_error(),
                           form=form,
                           version=version.__version__)
Ejemplo n.º 3
0
def login():
    if g.user is not None and g.user.is_authenticated():
        return redirect(url_for('index'))
    if request.method == 'POST':
        return oid.try_login('https://www.google.com/accounts/o8/id', ask_for = ['nickname', 'email'])
    return render_template('login.html', 
        title = 'Sign In')
Ejemplo n.º 4
0
def login():
    # g stores the login data
    # if there is already a logged in user - go to index
    if g.user is not None and g.user.is_authenticated:
        return redirect(url_for('index'))

    # LoginForm Class / how it renders
    form = LoginForm()

    #validate_on_submit does all the validation
    # tries to logina fter all is validated
    if form.validate_on_submit():
        session['remember_me'] = form.remember_me.data
    return oid.try_login(form.openid.data, ask_for=['nickname', 'email'])

    # flash shows a message on the next page
    # %s is for string
    # flash('Login requested for OpenID="%s", remember_me=%s' %
    # 	(form.openid.data, str(form.remember_me.data)))
    # return redirect('/index')

    return render_template('login.html',
                           title='Sign In',
                           form=form,
                           providers=app.config['OPENID_PROVIDERS'])
Ejemplo n.º 5
0
def login():
    if g.user is not None and g.user.is_authenticated:
        return redirect(url_for('index'))
    # we check if g.user is set to an authenticated user, and in that
    # case we redirect to the index page. The idea here is that if there
    # is a logged in user already we will not do a second login on top.
    # The g global is setup by Flask as a place to store and share data
    # during the life of a request. As I'm sure you guessed by now, we
    # will be storing the logged in user here.
    # The url_for function that we used in the redirect call is defined
    # by Flask as a clean way to obtain the URL for a given view function.
    # If you want to redirect to the index page you may very well use
    # redirect('/index'), but there are very good reasons to let Flask
    # build URLs for you.
    form = LoginForm()
    if form.validate_on_submit():
        # flash('Login requested for OpenID="%s", remember_me=%s' %
        #       (form.openid.data, str(form.remember_me.data)))
        # return redirect('/index')
        session['remember_me'] = form.remember_me.data
        return oid.try_login(form.openid.data, ask_for=['nickname', 'email'])
    return render_template(
        'login.html',
        title='Sign In',
        form=form,
        providers=app.config['OPENID_PROVIDERS']
    )  #Here we grab the configuration by looking it up in app.config with its key.
Ejemplo n.º 6
0
def login():
    # 如果已经登录就跳转到index
    # g在哪里?
    if g.user is not None and g.user.is_authenticated():
        return redirect(url_for('index'))
        
    form = LoginForm()
    # 点击的提交按钮
    if form.validate_on_submit():
        session['remember_me'] = form.remember_me.data
        return oid.try_login(form.openid.data, ask_for=['nickname', 'email'])

        # 
        # flash('login requested for OpenID="%s", remember_me=%s' %
        #       (form.openid.data, str(form.remember_me.data))
        #   )
        # return redirect('login')
    return render_template('login.html',
                           form = form,
                           title = 'Sign In',
                           providers=app.config['OPENID_PROVIDERS'],
                           nav = {
                               'link':'/login',
                               'title' : get_current_function_name(),   
                               }
                           )
Ejemplo n.º 7
0
def login():
    """
    登录视图
    :return:
    """
    if g.user is not None and g.user.is_authenticated:
        app.logger.debug('user %s has been login', g.user)
        return redirect(url_for('index'))

    form = LoginForm()
    if form.validate_on_submit():
        # flash('Login requested for OpendID="' + form.openid.data + '", remember_me=' + str(form.remember_me.data))
        # return redirect(url_for('index'))
        session['remember_me'] = form.remember_me.data

        app.logger.debug('try login by openid: %s', form.openid.data)

        return oid.try_login(form.openid.data, ask_for=['nickname', 'email'])

    app.logger.debug('sign in')

    return render_template('login.html',
                           title="Sign In",
                           form=form,
                           providers=app.config['OPENID_PROVIDERS'])
Ejemplo n.º 8
0
Archivo: views.py Proyecto: tbarron/fns
def login():
    """Does the login via OpenID.  Has to call into `oid.try_login`
    to start the OpenID machinery.
    """
    # if we are already logged in, go back to were we came from
    if logged_in_user() is not None:
        return redirect(oid.get_next_url())
    if request.method == 'POST':
        openid = request.form.get('openid')
        if not re.findall('^https*://', openid):
            openid = 'http://' + openid
        if openid:
            pape_req = pape.Request([])
            x = oid.try_login(openid, ask_for=['email', 'nickname'],
                              ask_for_optional=['fullname'],
                              extensions=[pape_req])
            return x
    form = LoginForm()
    if form.validate_on_submit():
        return redirect(oid.get_next_uril())

    msg = oid.fetch_error()
    if msg:
        flash(msg)
    elif fns_util.pu_time():
        flash('Please enter an openid')

    return render_template('login.html',
                           next=oid.get_next_url(),
                           error=oid.fetch_error(),
                           form=form,
                           version=version.__version__)
Ejemplo n.º 9
0
def login():

    # if the user is already authenticated, load the homepage and skip the login page
    if g.user is not None and g.user.is_authenticated():
        return redirect(url_for('index'), code=302)

    # load the login WTForm
    form = LoginForm()

    # if the form was submitted, validate submission and try to login using OpenID
    if form.validate_on_submit():
        session['remember_me'] = form.remember_me.data
        return oid.try_login(form.openid.data, ask_for = ['nickname', 'email'])

    # otherwise, the user needs to be shown the login form
    # check the request type and render accordingly
    if request.method == 'GET':
        return render_template('first.html',
            template_to_load = 'login.html', 
            title = 'Sign In',
            form = form)
    else:
        return render_template('login.html',
            title = 'Sign In',
            form = form)
Ejemplo n.º 10
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():
        openid = request.form['openid']
        user = MyProfile.query.filter_by(nickname=openid).first()
        if user is None:
            return redirect(request.args.get('next') or url_for('index'))
        elif openid == user.nickname and user is not None:
            session['remember_me'] = form.remember_me.data
            oid.try_login(openid, ask_for=['nickname', 'email'])
            login_user(user)
            return redirect(url_for("index"))
 
    return render_template('login.html', title='Sign In',form=form, providers=app.config['OPENID_PROVIDERS'])
Ejemplo n.º 11
0
def login():
    if g.user is not None and g.user.is_authenticated:
        return redirect(url_for('index'))
    form1 = LoginForm()
    form2 = LoginForm2()
    if form1.validate_on_submit():
        session['remember_me'] = form1.remember_me.data
        return oid.try_login(form1.openid.data, ask_for=['nickname', 'email'])
    if form2.validate_on_submit():
        session['remember_me'] = form2.remember_me.data
        user = User.query.filter_by(nickname=form2.nickname.data).first()
        if user.email == form2.mail.data:
            #u = User(nickname=form2.nickname.data, email=form2.mail.data, role=ROLE_USER)
            #db.session.add(u)
            #db.session.commit()
            # make the user follow him/herself
            #db.session.add(u.follow(u))
            #db.session.commit()
            login_user(user, remember=form2.remember_me.data)
            flash('Log in - success!')
            return redirect(url_for('index'))
    return render_template('login.html',
                           title='Sign In',
                           form=form1,
                           form2=form2,
                           providers=app.config['OPENID_PROVIDERS'])
Ejemplo n.º 12
0
def login():
    # does this handle the auto login? if g.user is present?
    if g.user is not None and g.user.is_authenticated:
        return redirect(url_for('index'))

    form = LoginForm()  # gets the object and instantiate it, the template then have access to the 'openid' and
    # 'remember_me' attributes of the object

    if form.validate_on_submit():  # uses the validator specified in the form object creation
        # returns a False if the fields has not been input when this handler is called

        # flash('Login requested for OpenID:"%s", remember_me="%s' %
        #       (form.openid.data, str(form.remember_me.data)))
        #  flash is being used here for debug, but in production it is useful for user feedback
        #  the flash messages have to be explicitly referenced in the template!!! use 'get_flashed_messages()
        #  these messages are removed from the message list once used?
        # return redirect('/index')  # if all is successful, navi to the index page

        session['remember_me'] = form.remember_me.data
        return oid.try_login(form.openid.data, ask_for=["nickname", "email"])

    return render_template('login.html',
                           title='Sign In',
                           form=form,
                           providers=app.config["OPENID_PROVIDERS"]
                           )
Ejemplo n.º 13
0
def login():
    # 如果已经登录就跳转到index
    # g在哪里?
    if g.user is not None and g.user.is_authenticated():
        return redirect(url_for('index'))

    form = LoginForm()
    # 点击的提交按钮
    if form.validate_on_submit():
        session['remember_me'] = form.remember_me.data
        return oid.try_login(form.openid.data, ask_for=['nickname', 'email'])

        #
        # flash('login requested for OpenID="%s", remember_me=%s' %
        #       (form.openid.data, str(form.remember_me.data))
        #   )
        # return redirect('login')
    return render_template('login.html',
                           form=form,
                           title='Sign In',
                           providers=app.config['OPENID_PROVIDERS'],
                           nav={
                               'link': '/login',
                               'title': get_current_function_name(),
                           })
Ejemplo n.º 14
0
def login():
    if g.user is not None and g.user.is_authenticated():
        return redirect(url_for('index'))
    form = LoginForm()
    formoid = LoginFormOid()
    error = ''
    if formoid.validate_on_submit():
        session['remember_me'] = formoid.remember_me.data
        return oid.try_login(formoid.openid.data, ask_for = ['nickname', 'email'])
    if form.validate_on_submit():

        #password = md5.md5(form.password.data).hexdigest()

        user = UserAccount.query.filter(UserAccount.username==form.username.data).first()

        if user is not None:

            salt = user.password.split('$')
            salt = salt[1]
            #print salt
            password = '******'+salt+'$'+hashlib.sha1(salt + form.password.data).hexdigest()
    #        password = hashlib.sha1(form.password.data).hexdigest()
            user = UserAccount.query.filter(and_(UserAccount.username==form.username.data, UserAccount.password==password)).first()

        if not user:
            error = 'Invalid username or password.'
        else:
            login_user(user, remember = form.remember_me.data)
            flash("Logged in successfully.")
            return redirect(request.args.get("next") or url_for("index"))

    return render_template('login.html', form=form, formoid=formoid, help_email=ADMINS[0], error=error, navigation=return_navigation(), providers = app.config['OPENID_PROVIDERS'], site_data=site_data())
Ejemplo n.º 15
0
def login():

    # checks to see if g.user is already logged in, redirects to index if so
    # the "g" global is set up by Flask as a place to store and share data during the life of a request
    # we will store the logged-in user here (in "g")
    if g.user is not None and g.user.is_authenticated():
        return redirect(url_for(
            'index'))  # "url_for" is a clean way to redirect to the index page

    # initiate the form object
    form = LoginForm()

    # here is where we validate and act on entered form data
    if form.validate_on_submit():

        # store the value of the "remember_me" boolean in the flask session
        # sessions are powerful -- stores data during request and any future requests made by same client (e.g. cookies)
        session['remember_me'] = form.remember_me.data

        # the "try_login" function initiates the openid login process
        return oid.try_login(form.openid.data, ask_for=['nickname', 'email'])
    return render_template('login.html',
                           title='Sign In',
                           form=form,
                           providers=app.config['OPENID_PROVIDERS'])
Ejemplo n.º 16
0
def login():
    if g.user is not None and g.user.is_authenticated:
        return redirect(url_for('index'))
    form1 = LoginForm1()
    form2 = LoginForm2()
    if form1.validate_on_submit():
        session['remember_me'] = form1.remember_me.data
        return oid.try_login(form1.openid.data, ask_for=['nickname', 'email'])
    if form2.validate_on_submit():
        session['remember_me'] = form2.remember_me.data
        email = form2.email.data
        user = User.query.filter_by(email=email).first()
        if not user:
            flash('该用户不存在')
        elif user.password != form2.password.data:
            flash('密码错误')
        else:
            login_user(user)
            flash("登陆成功")
            return redirect(url_for("index"))
    return render_template('login.html',
                           title='Sign In',
                           form1=form1,
                           form2=form2,
                           providers=app.config['OPENID_PROVIDERS'])  # 注册页面
Ejemplo n.º 17
0
def login():
    if g.user is not None and g.user.is_authenticated():
        return redirect(url_for('index'))
    form = LoginForm()
    if form.valicate_on_submit():
        session['remember_me'] = form.remember_me.data
        return oid.try_login(form.openid.data, ask_for=['nickname', 'email'])
Ejemplo n.º 18
0
def login():
    if g.user is not None and g.user.is_authenticated:  # g — это глобальный объект Flask, предназначенный для хранения и обмена данными во время жизни запроса. Именно в нём мы будем хранить данные о текущем пользователе
      return redirect(url_for('index'))
    form = LoginForm()
    if form.validate_on_submit():
        session['remember_me'] = form.remember_me.data
        return oid.try_login(form.openid.data, ask_for = ['nickname', 'email'])
    return render_template('login.html', title = 'Sign In', form = form, providers = app.config['OPENID_PROVIDERS'])
Ejemplo n.º 19
0
def login():
    if g.user is not None and g.user.is_authenticated():
        return redirect(url_for('index'))
    form = SigninForm()
    if form.validate_on_submit():
        session['remember_me'] = form.remember_me.data
        return oid.try_login(app.config['GOOGLE_OPENID'], ask_for=['nickname', 'email'])
    return render_template('signin.html', title='Sign In', form=form, )
Ejemplo n.º 20
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():
      session['remember_me'] = form.remember_me.data
      return oid.try_login(form.openid.data, ask_for = ['nickname', 'email'])
  return render_template('login.html', title = 'Sign In', form = form, providers = app.config['OPENID_PROVIDERS'])
Ejemplo n.º 21
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        print form.oid_provider.data
        oid_url = OPENID_PROVIDERS[form.oid_provider.data]
        return oid.try_login(oid_url, ask_for=['nickname', 'email'])

    return render_template('login.html', title='Sign In', form=form)
Ejemplo n.º 22
0
def login():
    if current_user.is_authenticated:
        return redirect(url_for("index"))
    form = LoginForm()
    if form.validate_on_submit():
        session["remember_me"] = form.remember_me.data
        return oid.try_login(form.openid.data, ask_for=["nickname", "email"])
    return render_template("login.html", title="Sign In", form=form, providers=app.config['OPENID_PROVIDERS'])
Ejemplo n.º 23
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():
        session["remember_me"] = form.remember_me.data
        return oid.try_login(form.openid.data, ask_for=["nickname", "email"])
    return render_template("login.html", title="Sign In", form=form, providers=app.config["OPENID_PROVIDERS"])
Ejemplo n.º 24
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():
        session['remember_me'] = form.remember_me.data
        return oid.try_login(form.openId.data, ask_for=['nickname', 'email'])
    return render_template('login.html', form=form, providers=app.config['OPENID_PROVIDERS'])
Ejemplo n.º 25
0
def login():
    if g.user is not None and g.user.is_authenticated():
        return redirect(url_for("index"))
    form=LoginForm()#Creo un'istanza della classe contenente il form di login
    if form.validate_on_submit():
        session["remember_me"] = form.rememberme.data
        return oid.try_login(form.openid.data,ask_for=["nickname","email"])
    return render_template("login.html",form=form,title="Sign in",providers=app.config["OPENID_PROVIDERS"])#Invio alla pagina di login il form creato con wtforms (che sarà gestito da jinja (vedi commenti html della pagina) e il titol,insieme ai provider di Openido
Ejemplo n.º 26
0
def login():
    if g.user is not None and g.user.is_authenticated:
        return redirect(url_for('index'))
    form = LoginForm()
    print app.config['OPENID_PROVIDERS']
    if form.validate_on_submit():
        openid = request.form.get('openid')
        if openid:
        # user = MyProfile.query.filter_by(username=username).first()
        # if user.username==form.username.data and user.password==form.password.data:
        #     userid = MyProfile.query.get(int(id))
        #     loggeduser =load_user(userid)
        #     login_user(loggeduser)
            session['remember_me'] = form.remember_me.data
            oid.try_login(form.openid.data, ask_for=['username', 'password'])
            return redirect(request.args.get("next") or url_for("home"))
    return render_template('login.html', title='Sign In',form=form, providers=app.config['OPENID_PROVIDERS'])
Ejemplo n.º 27
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():
        session['remember_me'] = form.remember_me.data
        return oid.try_login(form.openid.data, ask_for = ['nickname', 'email'])  # запускает процесс авторизации с помощью Flask-OpenID

    return render_template('login.html', title = 'Sign In', form = form,  providers = app.config['OPENID_PROVIDERS'])
Ejemplo n.º 28
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        session['remember_me'] = form.remember_me.data
        return oid.try_login(form.openid.data, ask_for = ['nickname', 'email'])
    return render_template('login.html',
        title = 'Sign In',
        form = form,
        providers = app.config['OPENID_PROVIDERS'])
Ejemplo n.º 29
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():
        session['remember_me'] = form.remember_me.data
        return oid.try_login('https://www.google.com/accounts/o8/id',
                             ask_for = ['nickname', 'email', 'fullname', 'image'])
    return render_template('login.html', title = 'Sign In', form = form)
Ejemplo n.º 30
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():
		session['remember_me'] = form.remember_me.data
		return oid.try_login(form.openid.data, ask_for=['nickname', 'email'])
		# flash('Login requested for OpenID="%s", remember_me=%s' % (form.openid.data, str(form.remember_me.data)))
	return render_template('login.html', title = 'Sign In', form = form, providers = app.config['OPENID_PROVIDERS'])
Ejemplo n.º 31
0
def oid_login():
    if g.user is not None:
        return redirect(oid.get_next_url())
    if request.method == 'POST':
        openid = request.form.get('openid')
        if openid:
            return oid.try_login(openid, ask_for=['email', 'nickname'],
                                 ask_for_optional=['fullname'])
    return render_template('web/index.html', next=oid.get_next_url(),
                           error=oid.fetch_error())
Ejemplo n.º 32
0
def login():
    if g.user is not None and g.user.is_authenticated:
        return redirect('/index')
    form = forms.LoginForm()
    if form.validate_on_submit():
        session['remember_me'] = True
        return oid.try_login(settings.OPENID['launchpad']['openid'],
                             ask_for=['nickname', 'email'])
    return render_template('login.html', form=form,
                           providers=settings.OPENID['launchpad']['url'])
Ejemplo n.º 33
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():
        session["remember_me"] = form.rememberme.data
        return oid.try_login(form.openid.data, ask_for=["nickname", "email"])
        # flash('Login requested for OpenID="%s", remember me=%s' % (form.openid.data,str(form.rememberme.data)))
        # return redirect('/index')
    return render_template("login.html", title="Sign In", form=form, providers=app.config["OPENID_PROVIDERS"])
Ejemplo n.º 34
0
def login():
    if g.user is not None:
        return redirect(oid.get_next_url())

    form = LoginForm()
    if form.validate_on_submit():
        return oid.try_login(form.openid.data)
    return render_template('login.html',
                           form=form,
                           next=oid.get_next_url(),
                           error=oid.fetch_error())
Ejemplo n.º 35
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():
        session['remember_me'] = form.remember_me.data
        return oid.try_login(form.openid.data, ask_for=['nickname', 'email'])
    return render_template('login.html',
                           title='Sign In',
                           form=form,
                           providers=['google', 'yahoo'])
Ejemplo n.º 36
0
def login():
    ###if g.user is not None and g.user.is_authenticated:
    ###	return redirect('index.html')
    form = LoginForm()
    if form.validate_on_submit():
        session['remember_me'] = form.remember_me.data
        return oid.try_login(form.openid.data, ask_for=['nickname', 'email'])
    return render_template(
        'login.html',
        title='Baromontres - login',
    )
Ejemplo n.º 37
0
def login():
    if g.user is not None and g.user.is_authenticated:
        return redirect('/index')
    form = forms.LoginForm()
    if form.validate_on_submit():
        session['remember_me'] = True
        return oid.try_login(settings.OPENID['launchpad']['openid'],
                             ask_for=['nickname', 'email'])
    return render_template('login.html',
                           form=form,
                           providers=settings.OPENID['launchpad']['url'])
Ejemplo n.º 38
0
def login():
    form = LoginForm()
    if form.validate_on_submit():
        print form.oid_provider.data
        oid_url = OPENID_PROVIDERS[form.oid_provider.data]
        return oid.try_login(oid_url, 
            ask_for = ['nickname', 'email'])
        
    return render_template('login.html', 
        title = 'Sign In',
        form = form)
Ejemplo n.º 39
0
def login():
    if g.user is not None and g.user.is_authenticated():  #do we have a valid logged in user?
        return redirect(url_for('index'))		#redirect to index
    form = LoginForm()
    if form.validate_on_submit():
        session['remember_me'] = form.remember_me.data  #store remember me box of form to session variable
        return oid.try_login(form.openid.data, ask_for = ['nickname', 'email'])  #openID login call
    return render_template('login.html', 
        title = 'Sign In',
        form = form,
        providers = app.config['OPENID_PROVIDERS'])
Ejemplo n.º 40
0
def login():
    lForm = LoginForm()

    # If the page was reached by a post request from the login form
    # if request.method == 'POST' and not sForm.validate_on_submit():
    if lForm.validate_on_submit():
        session['remember_me'] = lForm.remember_me.data
        flash('You have been successfully logged in', 'success')
        return oid.try_login(lForm.openid.data, ask_for=['nickname', 'email'])

    flash('Your openID was not recognised', 'error')
    return redirect(oid.get_next_url())
Ejemplo n.º 41
0
def login():
    if g.user is not None and g.user.is_authenticated():
        return redirect(url_for('index')) 	# url_for() -> Flask vrne url za view 'index'
    form = LoginForm()
    if form.validate_on_submit():
        session['remember_me'] = form.remember_me.data 	# Flask session - shranjeni podatki so na voljo za vse requeste tega userja
        return oid.try_login(form.openid.data, ask_for=['nickname', 'email']) # poslje podatke iz openid form do openid providerja,
		#od njega dobi podatke o 'nickname' in 'email' uporabnika. Ce je login uspese, poslje response funkciji oid.after_login
    return render_template('login.html', 
                           title='Sign In',
                           form=form,
                           providers=app.config['OPENID_PROVIDERS'])
Ejemplo n.º 42
0
def login():
    # 检查 g.user 是否被设置成一个认证用户
    if g.user is not None and g.user.is_authenticated:
        return redirect(url_for("index"))

    form = LoginForm()

    if form.validate_on_submit():
        session["remember_me"] = form.remember_me.data
        return oid.try_login(form.openid.data, ask_for=["nickname", "email"])

    return render_template("login.html", form=form)
Ejemplo n.º 43
0
def login():
  if flask.g.user is not None:
    return flask.redirect(oid.get_next_url())
  if flask.request.method == "POST":
    openid = flask.request.form.get("openid")
    if openid:
      return oid.try_login(openid, ask_for=["email", "fullname", "nickname"])
  # Display the errors on the page using the standard flash mechanism
  error = oid.fetch_error()
  if error:
    flask.flash(error, "alert-error")
  return flask.render_template("login.html", next=oid.get_next_url())
Ejemplo n.º 44
0
def login():
    if g.user is not None and g.user.is_authenticated():
        return redirect(url_for('home'))

    form = LoginForm()
    if form.validate_on_submit():
        session['remember_me'] = form.remember_me.data
        return oid.try_login(form.openid.data, ask_for=['nickname', 'email'], ask_for_optional=['fullname'])
    return render_template('auth/login.html',
                           title='Sign In',
                           form=form,
                           providers=settings.OPENID_PROVIDERS)
Ejemplo n.º 45
0
def login():
	if g.user is not None and g.user.is_authenticated():
		return redirect(url_for('index'))
	form = LoginForm()
	title = 'Sign In'
	providers = app.config['OPENID_PROVIDERS']
	if form.validate_on_submit():
	#	flash('OpenID: '+form.openid.data)
	#	flash('Cookie: '+str(form.remember_me.data))
		session['remember_me']=form.remember_me.data
		return oid.try_login(form.openid.data, ask_for = ['nickname', 'email'])
	return render_template("login.html", title=title, form=form, user=g.user, time=g.time, providers=providers)
Ejemplo n.º 46
0
def login():
    #if g.user is an authenticated user then we redirect to the chat page (makes sure we do not do a second login)
    if g.user is not None and g.user.is_authenticated():
        return redirect(url_for('chat'))
    form = LoginForm()
    if form.validate_on_submit():
        session['remember_me'] = form.remember_me.data
        return oid.try_login(form.openid.data, ask_for = ['nickname', 'email'])
    return render_template('login.html',
            title = 'Sign In',
            form = form,
            providers = app.config['OPENID_PROVIDERS'])
Ejemplo n.º 47
0
def login():
    form = forms.LoginForm()

    if g.user:
        if not g.user.is_anonymous():
            return redirect("/list_cars")

    if request.method == 'POST':
        oid_url = config.OPENID_PROVIDERS[form.oid_provider.data]
        return oid.try_login(oid_url, ask_for=['nickname', 'email'])

    return render_template('login.html', title='Sign In', form=form)
Ejemplo n.º 48
0
def servicelogin():
    if g.user is not None and g.user.is_authenticated:
        return redirect(url_for('index'))
    form = ServiceLoginForm()
    if form.validate_on_submit():
        # session['remember_me'] = form.remember_me.data
        session['remember_me'] = True
        return oid.try_login(form.openid.data, ask_for=['username', 'email'])
    return render_template('servicelogin.html',
                           title='Sign In',
                           form=form,
                           providers=PROVIDERS)
Ejemplo n.º 49
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():
        session['remember me'] = form.remember_me.data
        return oid.try_login(form.openid.data, ask_for=['username', 'email'])
    return render_template('login.html',
                           title='Sign In',
                           form=form,
                           providers=['facebook', 'google'])
Ejemplo n.º 50
0
def login():
    if g.user is not None and g.user.is_authenticated():
        return redirect(url_for('index'))
    form = SigninForm()
    if form.validate_on_submit():
        session['remember_me'] = form.remember_me.data
        return oid.try_login(app.config['GOOGLE_OPENID'],
                             ask_for=['nickname', 'email'])
    return render_template(
        'signin.html',
        title='Sign In',
        form=form,
    )
Ejemplo n.º 51
0
def login():
    # 全局变量g,在一个request周期中,用来存储和共享数据,将把已登录用户放到g中
    if g.user is not None and g.user.is_authenticated:  # 检测用户是否已经经过登录认证,如果一个用户已经登录了不让做二次登录
        return redirect(url_for('index'))
    form = LoginForm()
    if form.validate_on_submit():
        session['remember_me'] = form.remember_me.data
        # 通过openid来执行用户认证
        return oid.try_login(form.openid.data, ask_for=['nickname', 'email'])
    return render_template('login.html',
                           title='Sign In',
                           form=form,
                           providers=app.config['OPENID_PROVIDERS'])
Ejemplo n.º 52
0
def login():# Flask 中的 g 全局变量是一个在请求生命周期中用来存储和共享数据。
    if g.user is not None and g.user.is_authenticated:
    # flask_login 0.3之后将authenticated从函数更改为属性,把g.user.is_authenticated() 修改为g.user.is_authenticated就行了。
        return redirect(url_for('index'))
    form = LoginForm()
    if form.validate_on_submit():
        flash('登陆请求的OpenID = "' + form.openid.data + '", 记住我 = ' + str(form.remember_me.data))
        session['remember_me'] = form.remember_me.data
        return oid.try_login(form.openid.data, ask_for = ['nickname', 'email'])
    return render_template('login.html',
        title = 'Login',
        form = form,
        providers = app.config['OPENID_PROVIDERS'])
Ejemplo n.º 53
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():
        session["remember_me"] = form.remember_me.data
        # flash("Login requested for OpenID='" + form.openid.data + "', remember_me" + str(form.remember_me.data))
        # return redirect('/index')
        return oid.try_login(form.openid.data, ask_for=['nickname', 'email'])
    return render_template('login.html',
                           title="Sign In",
                           form=form,
                           providers=app.config['OPENID_PROVIDERS'])
Ejemplo n.º 54
0
def login():
	if g.user is not None and g.user.is_authenticated:
		flash(gettext('log out please'))
		# (u'你已经登录,先退出!')
		return redirect(url_for('index'))
	form = LoginForm()
	if form.validate_on_submit():
		#app.logger.error(form.remember_me.data)
		session['remember_me'] = form.remember_me.data
		return oid.try_login(form.openid.data, ask_for=['nickname', 'email'])
	return render_template('login.html',
							title='Sign in',
							form=form,
							providers=app.config['OPENID_PROVIDERS'])
Ejemplo n.º 55
0
def login():
    if g.user is not None and g.user.is_authenticated():
        user = g.user
        nickname = user.nickname.upper()
        return render_template('album_index.html', nickname=nickname)

    form = LoginForm()
    if form.validate_on_submit():

        return oid.try_login(form.openid.data, ask_for=['nickname', 'email'])
    return render_template('login.html',
                           title='Sign In',
                           form=form,
                           providers=app.config['OPENID_PROVIDERS'])
Ejemplo n.º 56
0
def login():
    if g.user is not None and g.user.is_authenticated():
        return redirect(url_for('home'))

    form = LoginForm()
    if form.validate_on_submit():
        session['remember_me'] = form.remember_me.data
        return oid.try_login(form.openid.data,
                             ask_for=['nickname', 'email'],
                             ask_for_optional=['fullname'])
    return render_template('auth/login.html',
                           title='Sign In',
                           form=form,
                           providers=settings.OPENID_PROVIDERS)
Ejemplo n.º 57
0
def login():
    if g.user is not None and g.user.is_authenticated:  #g is global
        return redirect(url_for('index'))
    form = LoginForm()
    #will validate as False with no data, so the form will be rendered
    #if validates successfully will redirect
    #if doesn't validate will render form again
    if form.validate_on_submit():
        #store boolean in flask session
        session['remember_me'] = form.remember_me.data
        return oid.try_login(form.openid.data, ask_for=['nickname', 'email'])
    return render_template('login.html',
                           title='Sign In',
                           form=form,
                           providers=app.config['OPENID_PROVIDERS'])
Ejemplo n.º 58
0
def login():
    if g.user is None:
        print 'user is none'
    else:
        print 'user is not none'

    if g.user is not None and g.user.is_authenticated:
        return redirect(url_for('index'))
    form = LoginForm() #实例化一个对象form,不通过new
    #当表单正在展示给用户的时候调用它,它会返回 False.
    if form.validate_on_submit():
        print form.remember_me.data
        session['remember_me'] = form.remember_me.data #这是一个布尔值
        return oid.try_login(form.openid.data, ask_for=['nickname', 'email'])
    return render_template('login.html', title='Sign In', form=form, providers=app.config['OPENID_PROVIDERS'])
Ejemplo n.º 59
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():
        session['remember_me'] = form.remember_me.data
        return oid.try_login(form.openid.data, ask_for=['nickname', 'email'])
        # flash('Login requested for OpenID="' +
        #       form.openid.data + '", remember_me=' +
        #       str(form.remember_me.data))
        # return redirect('/index')
    return render_template("login.html",
                           title='Sign In',
                           form=form,
                           providers=app.config['OPENID_PROVIDERS'])