コード例 #1
0
 def logged_in(self):
   """Returns true if a user is currently logged in, false otherwise."""
   token = os.getenv('HTTP_AUTHORIZATION')
   if token:
     return UserToken.get('', 'bearer', token) is not None
   else:
     return self.auth.get_user_by_session() is not None
コード例 #2
0
ファイル: cronjobs.py プロジェクト: nidzo732/SecureMessaging
 def get(self):
     ageLimit = datetime.datetime.now() - datetime.timedelta(days=1)
     targetTokensQuery = UserToken.query(UserToken.created < ageLimit)
     targetTokens = targetTokensQuery.iter()
     for targetToken in targetTokens:
         targetToken.key.delete()
     self.response.write(RESPONSE_OK)
コード例 #3
0
 def current_user(self):
   """Returns currently logged in user"""
   token = os.getenv('HTTP_AUTHORIZATION')
   if token:
     user_token = UserToken.get('', 'bearer', token)
     return self.auth.store.user_model.get_by_id(int(user_token.user))
   user_dict = self.auth.get_user_by_session()
   return self.auth.store.user_model.get_by_id(user_dict['user_id'])
コード例 #4
0
def get_old_signup_tokens():
    """ Return query with subject 'signup' """

    expiredTokensQuery = UserToken.query(
        UserToken.subject == 'signup', UserToken.created <=
        (datetime.datetime.utcnow() - datetime.timedelta(days=2)))
    expiredTokens = expiredTokensQuery.fetch(keys_only=True)
    return expiredTokens
コード例 #5
0
def get_old_auth_tokens():
    """ Return query with subject 'auth' """

    expiredTokensQuery = UserToken.query(
        UserToken.subject == 'auth', UserToken.created <=
        (datetime.datetime.utcnow() - datetime.timedelta(weeks=3)))
    expiredTokens = expiredTokensQuery.fetch(keys_only=True)
    return expiredTokens
コード例 #6
0
ファイル: auth.py プロジェクト: adamjmcgrath/fridayfilmclub
  def _auth_token(self, provider=None):
    """Used as a replacement to _auth_<provider>_callback to create a token
    based login flow for mobiles.
    """
    self.session['username'] = self.request.get('username')
    
    cfg = self.PROVIDERS.get(provider, (None,))
    meth = self._auth_method(cfg[0], 'callback')
    # Get user profile data and their access token
    user_data, auth_info = meth(provider, *cfg[-1:])
    # The rest should be implemented by the actual app
    user = self._login_user(user_data, auth_info, provider)

    # Set token
    user_data['token'] = UserToken.create(user.key.id(), 'bearer').token

    return self.render_json(user_data)
コード例 #7
0
ファイル: tasks.py プロジェクト: adamjmcgrath/fridayfilmclub
  def get(self):
    # 'auth' Tokens expire after 3 months, 'bearer' after 1 year.
    now = datetime.datetime.utcnow()
    three_months_ago = now - datetime.timedelta(3 * (365/12))
    one_year_ago = now - datetime.timedelta(365)
    expired_tokens = UserToken.query(
      ndb.OR(ndb.AND(UserToken.subject == 'auth',
                     UserToken.created <= three_months_ago),
             ndb.AND(UserToken.subject == 'bearer',
                     UserToken.created <= one_year_ago))
    )

    while True:
      logging.info('Deleting user tokens')
      keys = expired_tokens.fetch(100, keys_only=True)
      if len(keys) > 0:
        ndb.delete_multi(keys)
      else:
        break
コード例 #8
0
def get_all_signup_tokens():
    """ Return query with subject 'signup' """

    signupTokensQuery = UserToken.query(UserToken.subject == 'signup')
    signupTokens = signupTokensQuery.fetch()
    return signupTokens
コード例 #9
0
ファイル: models.py プロジェクト: elsigh/levels
 def oauth2_token(self):
     return UserToken.query(UserToken.user == self.key.id()).get().token
コード例 #10
0
ファイル: login.py プロジェクト: ChaoticNoise/GO2
def get_old_signup_tokens():
    """ Return query with subject 'signup' """

    expiredTokensQuery = UserToken.query(UserToken.subject=='signup', UserToken.created <= (datetime.datetime.utcnow() - datetime.timedelta(days=2)))
    expiredTokens = expiredTokensQuery.fetch(keys_only=True)
    return expiredTokens
コード例 #11
0
ファイル: login.py プロジェクト: ChaoticNoise/GO2
def get_all_signup_tokens():
    """ Return query with subject 'signup' """

    signupTokensQuery = UserToken.query(UserToken.subject=='signup')
    signupTokens = signupTokensQuery.fetch()
    return signupTokens
コード例 #12
0
ファイル: usermodel.py プロジェクト: nidzo732/SecureMessaging
 def deleteRecoveryToken(self, token):
     UserToken.get(self.getId(), "recovery", token).key.delete()
コード例 #13
0
ファイル: usermodel.py プロジェクト: nidzo732/SecureMessaging
 def recoveryToken(self):
     return UserToken.create(self.getId(), "recovery").token
コード例 #14
0
ファイル: auth.py プロジェクト: Yury191/hyperAdmit
    def post(self):

        self.response.headers['Content-Type'] = "application/json"

        # Does e-mail already exist?
        jsn = json.loads(self.request.body)
        email = jsn['email']
        password = jsn['password']
        first_name = jsn['first_name']
        last_name = jsn['last_name']
        phone = jsn['phone']

        query = User.query(User.email == email)
        users = query.fetch()

        if users:
            msg = 'Unable to create user.  Duplicate email: %s' % email
            self.send_response(self.RESPONSE_CODE_400, msg, "")
            return

        # Create Stripe customer
        stripe.api_key = utils.get_stripe_api_key()
        stripe_customer = stripe.Customer.create()
        stripe_customer_id = stripe_customer.id

        # If stripe customer Id doesn't exist, set to None
        if not stripe_customer_id:
            stripe_customer_id = None




        # Create a user
        unique_properties = ['email']
        user_data = self.user_model.create_user(email,
                                                unique_properties,
                                                email=email,
                                                password_raw=password,
                                                first_name=first_name,
                                                last_name=last_name,
                                                phone=phone)

                                                #stripeCustomerId=stripe_customer_id

        # If user was not created, probably a duplicate email
        if not user_data[0]:  # user_data is a tuple
            msg = 'Unable to create user.  Duplicate email: %s' % email
            self.send_response(self.RESPONSE_CODE_400, msg, "")
            return

        # New user created.  Get user at index 1
        user = user_data[1]

        user_dict = user.to_dict()

        user_id = user.get_id()
        token = UserToken.create(user_id, subject='auth', token=None)

        user_dict['token'] = str(token.token)
        user_dict['email'] = email

        del user_dict['created']
        del user_dict['updated']
        print user_dict


        self.send_response(self.RESPONSE_CODE_200, "User Signed Up", user_dict)
コード例 #15
0
    def post(self):

        self.response.headers['Content-Type'] = "application/json"

        # Does e-mail already exist?
        jsn = json.loads(self.request.body)
        email = jsn['email']
        password = jsn['password']
        first_name = jsn['first_name']
        last_name = jsn['last_name']
        phone = jsn['phone']

        query = User.query(User.email == email)
        users = query.fetch()

        if users:
            msg = 'Unable to create user.  Duplicate email: %s' % email
            self.send_response(self.RESPONSE_CODE_400, msg, "")
            return

        # Create Stripe customer
        stripe.api_key = utils.get_stripe_api_key()
        stripe_customer = stripe.Customer.create()
        stripe_customer_id = stripe_customer.id

        # If stripe customer Id doesn't exist, set to None
        if not stripe_customer_id:
            stripe_customer_id = None

        # Create a user
        unique_properties = ['email']
        user_data = self.user_model.create_user(email,
                                                unique_properties,
                                                email=email,
                                                password_raw=password,
                                                first_name=first_name,
                                                last_name=last_name,
                                                phone=phone)

        #stripeCustomerId=stripe_customer_id

        # If user was not created, probably a duplicate email
        if not user_data[0]:  # user_data is a tuple
            msg = 'Unable to create user.  Duplicate email: %s' % email
            self.send_response(self.RESPONSE_CODE_400, msg, "")
            return

        # New user created.  Get user at index 1
        user = user_data[1]

        user_dict = user.to_dict()

        user_id = user.get_id()
        token = UserToken.create(user_id, subject='auth', token=None)

        user_dict['token'] = str(token.token)
        user_dict['email'] = email

        del user_dict['created']
        del user_dict['updated']
        print user_dict

        self.send_response(self.RESPONSE_CODE_200, "User Signed Up", user_dict)
コード例 #16
0
ファイル: login.py プロジェクト: ChaoticNoise/GO2
def get_old_auth_tokens():
    """ Return query with subject 'auth' """

    expiredTokensQuery = UserToken.query(UserToken.subject=='auth', UserToken.created <= (datetime.datetime.utcnow() - datetime.timedelta(weeks=3)))
    expiredTokens = expiredTokensQuery.fetch(keys_only=True)
    return expiredTokens
コード例 #17
0
 def get(self):
     query = UserToken.query()
     query = query.filter(UserToken.updated < datetime.now() - timedelta(days=14))
     auth_token_keys = map(lambda t: t.key, query.fetch())
     ndb.delete_multi(auth_token_keys)
     logging.info("Cleaned up %d auth tokens" % len(auth_token_keys))