Esempio n. 1
0
def myschedules_app(org_id, location_id, role_id, user_id):

    # verify route exists
    user = RoleToUser.query.join(Role).join(Location).join(
        Organization).filter(RoleToUser.user_id == user_id, Role.id == role_id,
                             Location.id == location_id,
                             Organization.id == org_id).first()

    RoleToUser.query.filter_by(role_id=role_id,
                               user_id=user_id,
                               archived=False).first_or_404()

    if user is None:
        abort(404)

    # check if sudo or logged in as user
    if not (current_user.is_sudo() or current_user.id == user_id):
        return abort(403)

    current_user.track_event("visited_myschedules")
    current_user.ping(org_id=org_id)
    resp = make_response(
        render_template("myschedules.html",
                        api_token=current_user.generate_api_token(),
                        org_id=org_id,
                        location_id=location_id,
                        role_id=role_id,
                        user_id=user_id))
    resp.headers["Cache-Control"] = "no-store"
    return resp
Esempio n. 2
0
def before_request():
	if current_user.is_authenticated:
	    current_user.ping()   # Update logged-in user access time
	    if not current_user.confirmed \
	            and request.endpoint[:5] != 'auth.' \
	            and request.endpoint != 'static':   # Filter unconfirmed accounts
	        return redirect(url_for('auth.unconfirmed'))   
Esempio n. 3
0
def berore_request():
    if current_user.is_authenticated:
        current_user.ping()
        if not current_user.confirmed \
            and request.endpoint == 'writepost':
            flash(u'请确认你的邮箱地址')
            return redirect(url_for('.unconfirmed'))
Esempio n. 4
0
def before_request():
    if current_user.is_authenticated:
        current_user.ping()
        if not current_user.confirmed \
		and request.endpoint[:5] != 'auth.' \
                and request.endpoint != 'static':
            return render_template('auth/unconfirmed.html')
Esempio n. 5
0
def before_request():
    if current_user.is_authenticated:      #所以认证后登陆了,过了这关,
        current_user.ping()
        if not current_user.confirmed and request.endpoint[:5]!='auth.' and request.endpoint!='static':
            #flash(u'还没验证')
            #print current_user.confirmed    #测试用的,不知是不是重新登陆
            return redirect(url_for('auth.unconfirmed'))
Esempio n. 6
0
def before_request():
    if current_user.is_authenticated:
        current_user.ping()
        #if request.endpoint[:5] != 'auth.':
            #redirect(url_for('auth.login'))
    else:
        pass
Esempio n. 7
0
def before_request():
    if current_user.is_authenticated:
        current_user.ping()
        if not current_user.confirmed \
            and request.endpoint[:5] != 'auth.' \
            and request.endpoint != 'static':
        return redirect(url_for('auth.unconfirmed'))


@auth.route('/login', methods=['GET', 'POST'])
def login():
    form = LoginForm()
    if form.validate_on_submit():
        user = User.query.filter_by(email=form.email.data).first()
        if user is not None and user.veryfy_password(form.password.data):
            login_user(user, form.remember_me.data)
            return redirect(request.args.get('next') or url_for('main.index'))
        flash('无效的用户名或密码')
    return render_template('auth/login.html', form=form)


@auth.route('/logout')
@login_required
def logout():
    logout_user()
    flash('您已经退出登录')
    return redirect(url_for('main.index'))
Esempio n. 8
0
def before_request():
    if current_user.is_authenticated:
        current_user.ping()
        if not current_user.confirmed \
            and request.endpoint[:5] != "auth." \
            and request.endpoint != "static":
                return redirect(url_for("auth.unconfirmed"))
Esempio n. 9
0
def before_request():
    if current_user.is_authenticated:
        current_user.ping()
        if not current_user.confirmed \
                and request.endpoint[:5] != 'auth.' \
                and request.endpoint != 'static':
            return redirect(url_for('auth.unconfirmed'))
Esempio n. 10
0
def before_request():
    if current_user.is_authenticated:
        current_user.ping() #update time
        # flash('current_user.ping()')
    if current_user.is_authenticated and not current_user.confirmed \
            and request.endpoint != 'static':
        return redirect(url_for('unconfirmed'))
Esempio n. 11
0
def before_request():
    if current_user.is_authenticated:
        current_user.ping()
        if not current_user.confirmed \
                and request.endpoint[:5] != 'auth.' \
                and request.endpoint != 'static':
            return redirect(url_for('auth.unconfirmed'))
Esempio n. 12
0
def before_request():
    if current_user.is_authenticated:
        current_user.ping()  # last_seen
        if not (current_user.confirmed and current_user.active) \
                and request.endpoint not in ["auth.unconfirmed",
                    "auth.resend_confirmation", "auth.logout", "auth.confirm"] \
                and request.endpoint != "static":
            return redirect(url_for("auth.unconfirmed"))
Esempio n. 13
0
def before_request():#      flask提供的before_request钩子,在用户确认之前,完成某些操作。
    #满足一下条件时before_app_request拦截权限的获取
    if current_user.is_authenticated :#        用户已登录
        current_user.ping()#每次用户登录都调用ping方法,用于更新last_seen值
        if not current_user.confirmed \
        and request.endpoint[:5] != 'auth.'\
        and request.endpoint != 'static':#      用户为确认,且请求的端点不在认证蓝本中
            return redirect(url_for('auth.unconfirmed'))#       重定向至/auth/unconfirmed路由
Esempio n. 14
0
def before_request():
    if current_user.is_authenticated():
        current_user.ping()
        print request.endpoint
        if not current_user.confirmed:
            if request.endpoint == None or request.endpoint[:5] != 'auth.':
                resend_confirmation()
                return redirect(url_for('auth.unconfirmed'))
Esempio n. 15
0
def before_request():
    if current_user.is_authenticated():
        current_user.ping()
        print request.endpoint
        if not current_user.confirmed:
            if request.endpoint == None or request.endpoint[:5] != 'auth.':
                resend_confirmation()
                return redirect(url_for('auth.unconfirmed'))
Esempio n. 16
0
def before_request():
    """请求前的执行函数
    """
    if current_user.is_authenticated():
        current_user.ping()  # 更新最后活跃时间
        if not current_user.confirmed \
                and request.endpoint[:5] != 'auth.':
            return redirect(url_for('auth.unconfirmed'))
Esempio n. 17
0
def before_request():
    if current_user.is_authenticated():
        # 登记用户活动时间
        current_user.ping()

        # 过滤用户请求
        if not current_user.confirmed and request.endpoint[:8] != "account." and request.endpoint != "static":
            return redirect(url_for("account.unconfirmed"))
Esempio n. 18
0
def before_request():
    if current_user.is_authenticated:
        #: ping is working for update the last_seen field!
        current_user.ping()
        if not current_user.confirmed \
                and request.endpoint[:5] != 'auth.' \
                and request.endpoint != 'static':
            return redirect(url_for('auth.unconfirmed'))
Esempio n. 19
0
def before_request():
    if current_user.is_authenticated:
        current_user.ping()
        if not current_user.confirmed and  \
        request.endpoint[0:7] != 'confirm' and request.endpoint[0:6] != 'logout' and request.endpoint[0:6] != 'index':
    #对于已经登录、没有确认、请求的页面不是令牌页面的 请求
        # return redirect(url_for('unconfirmed'))
        # print request.endpoint[0:6] is 'logout'
            return render_template('unconfirmed.html')
Esempio n. 20
0
def before_request():
    ''' 1.处理程序中过滤未确认的帐户  '''
    ''' 2.更新已登录用户的访问时间 '''
    if current_user.is_authenticated():
        current_user.ping()  #更新已登录用户的访问时间
        if not current_user.confirmed \
           and request.endpoint[:5] != 'auth.' \
           and request.endpoint != 'static':
            return redirect(url_for('auth.unconfirmed'))
Esempio n. 21
0
def before_request():
    # a user is logged in
    if current_user.is_authenticated:
        # ping logged-in user, for visit time
        current_user.ping()
        # not confirmed
        if not current_user.confirmed \
            and request.endpoint[:5] != 'auth.':    # not confirmed user just access the url 'auth/' (?)
            return redirect(url_for('auth.unconfirmed'))
Esempio n. 22
0
def before_request():  #定义全局变量
    # g.hot_post=Post().hotpost()
    # g.current_time=datetime.utcnow()
    if current_user.is_authenticated:
        current_user.ping()
        if not current_user.confirmed \
		and request.endpoint[:5] != 'auth.' \
                and request.endpoint != 'static':
            return render_template('auth/unconfirmed.html')
Esempio n. 23
0
def before_request():  #before request trigger
    ##is_authenticated is method of flask_login ,means login or logined
    if current_user.is_authenticated:
        current_user.ping()
        if not current_user.confirmed \
                and request.endpoint \
                and request.endpoint[:5] != 'auth.' \
                and request.endpoint != 'static':
            return redirect(url_for('auth.unconfirmed'))
Esempio n. 24
0
def before_request():
              ''' 1.处理程序中过滤未确认的帐户  '''
              ''' 2.更新已登录用户的访问时间 '''
              if current_user.is_authenticated():
                            current_user.ping()   #更新已登录用户的访问时间
                            if not current_user.confirmed \
                               and request.endpoint[:5] != 'auth.' \
                               and request.endpoint != 'static':
                                          return redirect(url_for('auth.unconfirmed'))
Esempio n. 25
0
def before_request():  #定义全局变量
    # g.hot_post=Post().hotpost()
    # g.current_time=datetime.utcnow()
    if current_user.is_authenticated:
        current_user.ping()
        if not current_user.confirmed \
  and request.endpoint[:5] != 'auth.' \
                and request.endpoint != 'static':
            return render_template('auth/unconfirmed.html')
Esempio n. 26
0
def resolve_confirm_status(current_user, token=None):
    if current_user.confirmed or current_user.confirm_token(token):
        current_user.ping()
        flash(f30)
        # Visit.create(**get_geodata())
        return 'proj.home2'
    else:
        if token: flash(f130 + ' ' + f131)
        else: flash(f130)
        return '.home'
Esempio n. 27
0
def resolve_confirm_status(current_user, token=None):
    if current_user.confirmed or current_user.confirm_token(token):
        current_user.ping()
        flash(f30)
        # Visit.create(**get_geodata())
        return 'proj.home2'
    else:
        if token: flash(f130 + ' ' + f131)
        else: flash(f130)
        return '.home'
Esempio n. 28
0
def before_request():
    """
    注册了一个函数,在每次请求前验证用户信息。
    """
    if current_user.is_authenticated:
        current_user.ping()
        if not current_user.confirmed \
            and request.endpoint[:5] != "auth."\
            and request.endpoint != 'static':
            return redirect(url_for("auth.unconfirmed"))
Esempio n. 29
0
def before_request():
    """
    注册了一个函数,在每次请求前验证用户信息。
    """
    if current_user.is_authenticated:
        current_user.ping()
        if not current_user.confirmed \
            and request.endpoint[:5] != "auth."\
            and request.endpoint != 'static':
            return redirect(url_for("auth.unconfirmed"))
Esempio n. 30
0
def before_request():
    # db.drop_all()
    # db.create_all()
    # db.session.commit()
    # Role.insert_roles()
    if current_user.is_authenticated:
        current_user.ping()
        if not current_user.confirmed \
                and request.endpoint[:5] != 'auth.' \
                and request.endpoint != 'static':
            return redirect(url_for('auth.unconfirmed'))
def before_request():
    if current_user.is_authenticated:
        current_user.ping()
        if not current_user.verify_auth_token(session['auth_token']):
            logout_user()
            flash('Your session has expired.')
            return redirect(url_for('auth.login'))
        if not current_user.confirmed \
                and request.endpoint[:5] != 'auth.' \
                and request.endpoint != 'static':
            return redirect(url_for('auth.unconfirmed'))
Esempio n. 32
0
def before_request():
    '''
    满足以下条件before_request()函数会拦截request请求
    1.用户已经登陆,且没有通过邮件进行认证
    2.用户请求的路由不是'auth'端点,不是静态文件
    '''
    if current_user.is_authenticated:
        # 更新用户最后登陆时间
        current_user.ping()
        if not current_user.confirmed and request.endpoint[:5] != 'auth.'and request.endpoint != 'static':
            return redirect(url_for('auth.unconfirmed'))
Esempio n. 33
0
def before_request():
    # db.drop_all()
    # db.create_all()
    # db.session.commit()
    # Role.insert_roles()
    if current_user.is_authenticated:
        current_user.ping()
        if not current_user.confirmed \
                and request.endpoint[:5] != 'auth.' \
                and request.endpoint != 'static':
            return redirect(url_for('auth.unconfirmed'))
Esempio n. 34
0
def before_request():
    if current_user.is_authenticated:
        current_user.ping()
        if not current_user.verify_auth_token(session.get('auth_token')):
            LogEvent.session_bad_auth_token(current_user)
            logout_user()
            flash_it(AuthMessages.SESSION_EXPIRED)
            return redirect(url_for('auth.login'))
        if (not current_user.confirmed and
                request.endpoint[:5] != 'auth.' and
                request.endpoint != 'static'):
            return redirect(url_for('auth.unconfirmed'))
Esempio n. 35
0
def before_request():
    '''
    满足以下条件before_request()函数会拦截request请求
    1.用户已经登陆,且没有通过邮件进行认证
    2.用户请求的路由不是'auth'端点,不是静态文件
    '''
    if current_user.is_authenticated:
        # 更新用户最后登陆时间
        current_user.ping()
        if not current_user.confirmed and request.endpoint[:
                                                           5] != 'auth.' and request.endpoint != 'static':
            return redirect(url_for('auth.unconfirmed'))
Esempio n. 36
0
def before_request():
    if current_user.is_authenticated():
        current_user.ping()
    #(1) 用户已登录( current_user.is_authenticated() 必须返回 True )。
    #(2) 用户的账户还未确认。
    #(3) 请求的端点(使用 request.endpoint 获取)不在认证蓝本中。访问认证路由要获取权
    #限,因为这些路由的作用是让用户确认账户或执行其他账户管理操作。
    if current_user.is_authenticated() \
            and not current_user.confirmed \
            and request.endpoint[:5] != 'auth.' \
            and request.endpoint != 'static':
        return redirect(url_for('auth.unconfirmed'))
Esempio n. 37
0
def before_request():
	'''
	before_app_request表示全局的请求钩子
	is_authenticated表示用户是否登录
	endpoint返回请求的端点
	'''
	if current_user.is_authenticated:
		current_user.ping()
		if not current_user.confirmed \
		and request.endpoint[:5] != 'auth.' \
		and request.endpoint != 'static':
			return redirect(url_for('auth.unconfirmed'))
Esempio n. 38
0
def before_request():
    if current_user.is_authenticated():
        current_user.ping()
    #(1) 用户已登录( current_user.is_authenticated() 必须返回 True )。
    #(2) 用户的账户还未确认。
    #(3) 请求的端点(使用 request.endpoint 获取)不在认证蓝本中。访问认证路由要获取权
    #限,因为这些路由的作用是让用户确认账户或执行其他账户管理操作。
    if current_user.is_authenticated() \
            and not current_user.confirmed \
            and request.endpoint[:5] != 'auth.' \
            and request.endpoint != 'static':
        return redirect(url_for('auth.unconfirmed'))
Esempio n. 39
0
def before_request():
	if current_user.is_authenticated:
		current_user.ping()
		#如果用户验证成功,则调用ping方法,last_seen会被加入到session中
		if not current_user.confirmed\
				and request.endpoint[:5] != 'auth.'\
				and request.endpoint != 'static':
		#当前用户已登录
		#当前用户还未验证
		#请求的路径不在认证蓝本中
		#请求的路径不是'static'
			return redirect(url_for('auth.unconfirmed'))
Esempio n. 40
0
def before_request():
    if current_user.is_authenticated:
        current_user.ping()
        #如果用户验证成功,则调用ping方法,last_seen会被加入到session中
        if not current_user.confirmed\
          and request.endpoint[:5] != 'auth.'\
          and request.endpoint != 'static':
            #当前用户已登录
            #当前用户还未验证
            #请求的路径不在认证蓝本中
            #请求的路径不是'static'
            return redirect(url_for('auth.unconfirmed'))
Esempio n. 41
0
def before_request():
    if current_user.is_authenticated():
        current_user.ping()
        if not current_user.confirmed \
                and request.endpoint[:5] != 'auth.' \
                and request.endpoint != 'static':
            return redirect(url_for('auth.unconfirmed'))

        #if the user is request salesmanager and is not granted by the admin,
        #sent redirect to salesmanager.ungranted
        if current_user.is_salesmanager() and current_user.to_be_confirm_salesmanager \
                and request.endpoint == 'salesmanager':
            return redirect(url_for('salesmanager.ungranted'))
Esempio n. 42
0
def before_request():
    # pydevd.settrace('192.168.56.1', port=22, stdoutToServer=True, stderrToServer=True)

    endpoint = 'None'
    if request.endpoint:
        endpoint = request.endpoint[:5]

    if current_user.is_authenticated:
        current_user.ping()
        if not current_user.confirmed and endpoint not in [
                'auth.', 'static', 'main.'
        ]:
            return redirect(url_for('auth.unconfirmed'))
Esempio n. 43
0
def load_user(apptype):
    g.user = current_user if current_user.is_authenticated() else None
    g.user_id = g.user.id if g.user else None
    if current_user and current_user.is_authenticated():
        current_user.ping()

    # lang = session['language'] if 'language' in session else 'uk'
    g.languages = Config.LANGUAGES

    g.lang = 'en'
    if 'HTTP_ACCEPT_LANGUAGE' in request.headers.environ:
        agent_languages = list(
            map(
                lambda l: re.compile("\s*;\s*q=").split(l),
                re.compile("\s*,\s*").split(
                    request.headers.environ['HTTP_ACCEPT_LANGUAGE'])))
        agent_languages.sort(key=lambda x: float(x[1]) if len(x) > 1 else 1,
                             reverse=True)
        for lng in agent_languages:
            if lng[0][0:2] in [l['name'] for l in Config.LANGUAGES]:
                g.lang = lng[0][0:2]
                break
    if g.user:
        g.lang = g.user.lang
    if 'language' in session:
        g.lang = session['language']

    if g.lang not in [l['name'] for l in Config.LANGUAGES]:
        g.lang = 'en'
    # = g.user.lang if g.user else lang

    g.portal = None
    g.portal_id = None
    g.portal_layout_path = ''
    g.protocol = Config.PROTOCOL

    g.debug = current_app.debug
    g.testing = current_app.testing

    for variable in g.db.query(ModelConfig).filter_by(server_side=1).all():
        var_id = variable.id
        if variable.type == 'int':
            current_app.config[var_id] = int(variable.value)
        elif variable.type == 'bool':
            current_app.config[var_id] = False if int(
                variable.value) == 0 else True
        else:
            current_app.config[var_id] = '%s' % (variable.value, )
Esempio n. 44
0
def manager_app(org_id):
    # Auth - are they sudo?
    organization = Organization.query.get_or_404(org_id)

    if current_user.is_sudo() or organization in current_user.manager_accounts(
    ):
        current_user.track_event("visited_manager")
        current_user.ping(org_id=org_id)
        resp = make_response(
            render_template("manager.html",
                            organization=organization,
                            api_token=current_user.generate_api_token()))
        resp.headers["Cache-Control"] = "no-store"
        return resp

    return abort(403)
Esempio n. 45
0
def before_request():
    if IsDeepDebug:
        print('--> before_request:is_authenticated:%s is_active:%s' %
              (current_user.is_authenticated, current_user.is_active))

    if not request.endpoint:
        return

    if current_user.is_authenticated and request.endpoint[:
                                                          5] != 'auth.' and request.endpoint != 'static':
        current_user.ping()
        if not current_user.confirmed:
            return redirect(url_for('auth.unconfirmed'))
        if not is_pwd_changed():
            current_user.unconfirmed()
            return redirect(url_for('auth.change_password'))
Esempio n. 46
0
def logout():
    '''
        I still do not know why I can not access the g.client
        when I set g.client = client in the callback().
        I think that they are in the same request..well not quite sure about that
    '''
    current_user.ping()
    logout_user()
    access_token = session['access_token']
    http_url = 'https://api.weibo.com/oauth2/revokeoauth2?access_token=%s' % access_token
    req = urllib2.Request(http_url)
    req.add_header('Accept-Encoding', 'gzip')
    req.add_header('Authorization', 'OAuth2 %s' % access_token)
    urllib2.urlopen(req)
    flash('You have been logged out.')
    return redirect(url_for('main.index'))
Esempio n. 47
0
def login():
    cashes = Cashes.query.filter_by(status=True).order_by('branch').all()
    if request.method == 'POST':

        username = request.form['username']
        password = request.form['password']
        selected_cash = request.form['select_ch'].upper()

        user = User.query.filter_by(username=username).first()

        if user is not None and user.verify_password(password) and user.status:
            login_user(user)
            current_user.cash = Cashes.query.filter(Cashes.branch == selected_cash).first()
            current_user.ping()
            return redirect(request.args.get('next') or url_for('main.index'))
        flash('Неверный пользователь или пароль. Попробуйте еще раз.')

    return render_template('auth/login.html', cashes=cashes)
Esempio n. 48
0
def load_user(apptype):
    g.user = current_user if current_user.is_authenticated() else None
    if current_user and current_user.is_authenticated():
        current_user.ping()

    # lang = session['language'] if 'language' in session else 'uk'
    g.languages = Config.LANGUAGES

    g.lang = 'en'
    if 'HTTP_ACCEPT_LANGUAGE' in request.headers.environ:
        agent_languages = list(map(lambda l: re.compile("\s*;\s*q=").split(l),
                                   re.compile("\s*,\s*").split(request.headers.environ['HTTP_ACCEPT_LANGUAGE'])))
        agent_languages.sort(key=lambda x: float(x[1]) if len(x) > 1 else 1, reverse=True)
        for lng in agent_languages:
            if lng[0][0:2] in [l['name'] for l in g.languages]:
                g.lang = lng[0][0:2]
                break
    if g.user:
        g.lang = g.user.lang
    if 'language' in session:
        g.lang = session['language']

    if g.lang not in [l['name'] for l in g.languages]:
        g.lang = 'en'
    # = g.user.lang if g.user else lang


    g.portal = None
    g.portal_id = None
    g.portal_layout_path = ''
    g.protocol = 'http:'

    g.debug = current_app.debug
    g.testing = current_app.testing

    for variable in g.db.query(ModelConfig).filter_by(server_side=1).all():
        var_id = variable.id
        if variable.type == 'int':
            current_app.config[var_id] = int(variable.value)
        elif variable.type == 'bool':
            current_app.config[var_id] = False if int(variable.value) == 0 else True
        else:
            current_app.config[var_id] = '%s' % (variable.value,)
Esempio n. 49
0
def before_request():
    """
    When a before_request or before_app_request callback returns a
    response or a redirect, Flask sends that to the client without invoking
    the view function associated with the request. This effectively
    allows these callbacks to intercept a request when necessary.

    From a blueprint, the before_request hook applies only to requests that
    belong to the blueprint. To install a hook for all application requests from a blueprint,
    the before_app_request decorator must be used instead.

    The requested endpoint (accessible as request.endpoint) is outside of the authentication
    blueprint. Access to the authentication routes needs to be granted, as
    those are the routes that will enable the user to confirm the account or perform
    other account management functions.

    This is really annoying. Change it so that it is only a flash.
    :return:
    """
    if current_user.is_authenticated():
        current_user.ping()
        if not current_user.confirmed and request.endpoint[:5] != 'auth.' and request.endpoint != 'static':
            return redirect(url_for('auth.unconfirmed'))
Esempio n. 50
0
def before_request():
    if current_user.is_authenticated:
        current_user.ping()
        if not current_user.confirmed and request.endpoint[:5]!='auth.' and request.enpoint!=
        'static':
        return redirect(url_for('auth.unconfirmed'))

# 只要发出任何请求,current_user就ping一下。如果没有confirmed 而且浏览了非auth 或 static的页面就返回 unconfirmed 页面。

@auth.route('/unconfirmed')
def unconfirmed():
    if current_user.is_anonymous or current_user.confirmed:
        return redirect(url_for('main.index'))
    return render_template('auth/unconfirmed.html')

# 如果当前用户是anonymous_user 或 已经confirmed,就不让看unconfirmed 页面了,直接跳转到主页。

@auth.route('/login',methods=['GET','POST'])
def login():
    form=LoginForm()
    if form.validate_on_submit():
        user=User.query.filter_by(email=form.email.data).first()
        if user is not None and user.verify_password(form.password.data):
            login_user(user,form.remember_me.data)
            # login_user第二个参数是是否写入cookie记住该用户。
            return redirect(request.args.get('next')or url_for('main.index'))

@auth.route('/logout')
@login_required
def logout():
    logout_user()
    flash('You have been logged out.')
    return redirect(url_for('main.index'))


@auth.route('/register',methods=['GET','POST'])
def register():
    form=RegistrationForm()
    if form.validate_on_submit():
        user=User(email=form.email.data,username=form.username.data,password=form.password.data)
        db.session.add(user)
        db.session.commit()
        token=user.generate_confirmation_token()
        send_email(user.email,'Confirm Your Account','auth/email/confirm',user=user,token=token)
        flash('A confirmation email has been sent to you by email.')
        return redirect(url_for('auth.login'))
    return render_template('auth/register.html',form=form)
#把注册信息添加入数据库.发送确认信。

@auth.route('/confirm/<token>')
@login_required
def confirm(token):
    if current_user.confirmed:
        return redirect(url_for('main.index'))
    if current_user.confirm(token):
        flash('You have confirmed your account.Thanks.')
    else:
        flash('The confirmation link is invalid or has expired.')
    return redirect(url_for('main.index'))

# 确认token

@auth.route('/confirm')
@login_required
def resend_confirmation():
    token=current_user.generate_confirmation_token()
    send_email(current_user.email,'Confirm Your Account','auth/email/confirm',user=current_user,token=token)
    flash('A new confirmation email has been sent to you by email.')
    return redirect(url_for('main.index'))



@auth.route('/change-password',methods=['GET','POST'])
@login_required
def change_password():
    form=ChangePasswordForm()
    if form.validate_on_submit():
        user=User.query.filter_by(email=form.email.data).first()
        if user:
            token=user.generate_reset_token()
            send_email(user.email,'Resset Your Password','auth/email/reset_password',user=user,token=token,next=request.args.get('next'))
            #这里不懂,send_email里有next.
        flash('An email with instructions to reset your password has benn sent to you.')
        return redirect(url_for('auth.login'))
    return render_template('auth/reset_password.html',form=form)

@auth.route('/reset/<token>',methods=['GET','POST'])
def password_reset(token):
    if not current_user.is_anonymous:
        return redirect(url_for('main.index'))
    form=PasswordResetForm()
    if form.validate_on_submit():
        user=User.query.filter_by(email=form.email.data).first()

        if user is None:
            return redirect(url_for('main.index'))
        if user.reset_password(token,form.password.data):
            flash('Your password has been updated.')
            return redirect(url_for('auth.login'))
        else:
            return redirect(url_for('main.index'))
    return render_template('auth/reset_password.html',form=form)

@auth.route('/change-email',methods=['GET','POST'])
@login_required
def change_email_request():
    form=ChangeEmailForm()
    if form.validate_on_submit():
        if current_user.verify_password(form.password.data):
            new_email=form.email.data
            token=current_user.generate_emaail_change_token(new_email)
            #此处的token里包含了新email.
            send_email(new_email,'Confirm your email address','auth/email/change_email',user=current_user,token=token)
            flash('An email with instructions to confirm your new email.')
            return redirect(url_for('main.index'))
        else:
            flash('Invalid email or password.')
    return render_template('auth/change_email.html',form=form)

@auth.route('/change-email/<token>')
@login_required
def change_email(token):
    if current_user.change_email(token):
        #这里写在User里的change_email函数会判定email是否符合,符合的话直接
        flash('Your email address has been updated.')
    else:
        flash('Invalid request.')
    return redirect(url_for('main.index'))
Esempio n. 51
0
def before_request():#在请求之前会调用这个钩子
	if current_user.is_authenticated():
		current_user.ping()
	if current_user.is_authenticated() and not current_user.confirmed and request.endpoint[:5] != 'auth.'\
			and request.endpoint != 'static':#endpoint是指端点,一般即指视图函数的函数名,static做端点名是指向静态文件,如css文件等
		return redirect(url_for('auth.unconfirmed'))
Esempio n. 52
0
def before_request():
    if current_user.is_authenticated:
        current_user.ping()
Esempio n. 53
0
def before_request():  #在请求之前会调用这个钩子
    if current_user.is_authenticated():
        current_user.ping()
    if current_user.is_authenticated() and not current_user.confirmed and request.endpoint[:5] != 'auth.'\
      and request.endpoint != 'static':#endpoint是指端点,一般即指视图函数的函数名,static做端点名是指向静态文件,如css文件等
        return redirect(url_for('auth.unconfirmed'))
Esempio n. 54
0
def before_request():
    if current_user.is_authenticated:
        current_user.ping()  # Update last seen.
        if not current_user.confirmed and request.endpoint[:5] != 'auth.':
            return redirect(url_for('auth.unconfirmed'))
Esempio n. 55
0
def before_request():
    if current_user.is_authenticated:
        current_user.ping()
Esempio n. 56
0
def before_request():
    if current_user.is_authenticated():
        current_user.ping()
        if not current_user.confirmed and request.endpoint[:5] != 'auth.' and request.endpoint != 'static' and \
                not (request.endpoint == 'tools.save_translate' or request.endpoint == 'tools.change_allowed_html' or request.endpoint == 'tools.update_last_accessed'):
            return redirect(url_for('auth.unconfirmed'))