示例#1
0
文件: user.py 项目: Zhinsta/Zhinsta
 def get(self):
     if has_login():
         return redirect(url_for('view.members'))
     redirect_uri = INSTAGRAM_REDIRECT_URI
     if request.args.get('uri', ''):
         redirect_uri += '?uri=' + request.args.get('uri')
     api = InstagramAPI(client_id=INSTAGRAM_CLIENT_ID,
                        client_secret=INSTAGRAM_CLIENT_SECRET,
                        redirect_uri=redirect_uri)
     redirect_uri = gevent.spawn(api.get_authorize_login_url,
                                 scope=INSTAGRAM_SCOPE)
     gevent.joinall([redirect_uri])
     try:
         redirect_uri = redirect_uri.get()
     except InstagramAPIError:
         return notfound(u'服务器暂时出问题了')
     return redirect(redirect_uri)
示例#2
0
文件: user.py 项目: Zhinsta/Zhinsta
 def get(self):
     if has_login():
         return redirect(url_for('view.show'))
     redirect_url = url_for('view.show')
     code = request.args.get('code', '')
     redirect_uri = INSTAGRAM_REDIRECT_URI
     if request.args.get('uri', ''):
         redirect_url = request.args.get('uri')
         redirect_uri += '?uri=' + redirect_url
     api = InstagramAPI(client_id=INSTAGRAM_CLIENT_ID,
                        client_secret=INSTAGRAM_CLIENT_SECRET,
                        redirect_uri=redirect_uri)
     try:
         access_token = api.exchange_code_for_access_token(code)
     except:
         return apierror()
     user = (UserModel.query
             .filter_by(ukey=access_token[1]['id']).first())
     if user:
         user.access_token = access_token[0]
         user.username = access_token[1]['username']
         user.pic = access_token[1]['profile_picture']
     else:
         user = UserModel(ukey=access_token[1]['id'],
                          username=access_token[1]['username'],
                          pic=access_token[1]['profile_picture'],
                          access_token=access_token[0])
         db.session.add(user)
         redirect_url = url_for('view.welcome')
     db.session.commit()
     admin = AdminModel.query.get(user.ukey)
     session.permanent = True
     session['ukey'] = user.ukey
     session['username'] = user.username
     session['access_token'] = user.access_token
     session['is_admin'] = True if admin else False
     return redirect(redirect_url)