Example #1
0
    def post(self):
        args = fbUserParser.parse_args()
        fb_id = args['fbid']
        fb_token = args['fbtoken']   
        if fb_id is None or fb_token is None:
           abort(400)

        fbuser_info = requests.get('https://graph.facebook.com/me?access_token=%s' %fb_token).json()
        if not fbuser_info.get('id') or fb_id != fbuser_info['id']:
            raise InvalidUsage('User info does not match',406)

        fb_email = args['fbemail']
        user = User.objects(email=fb_email).first()
        
        if user is None:
            user = User(email=fb_email, fb_id=fbuser_info['id'])
            user.save()
            
        profile = Profile.objects(user=user).first()
        if profile is None:
            profile = Profile(user=user)
            profile.save()

        rongToken = rongcloudToken(profile.id)
        token = user.generate_auth_token()
        redis_store.set(str(user.id), token)
        return {'token': token, 'rongToken' : rongToken}
Example #2
0
    def post(self):
        """
        Sign up with Facebook account and return a token
        """
        args = fbUserParser.parse_args()
        fb_id = args['fbid']
        fb_token = args['fbtoken']
        fb_email = args['fbemail']
        if fb_id is None or fb_token is None or fb_email is None:
            abort(400)

        # verify the user's facebook account using the facebook token
        fbuser_info = requests.get(
            'https://graph.facebook.com/me?access_token=%s' % fb_token).json()
        if not fbuser_info.get('id') or fb_id != fbuser_info['id']:
            abort(406)

        user = User(email=fb_email, fb_id=fb_id)
        try:
            user.save()
        except:
            return {'status': 'error', 'message': 'FBname has already existed'}

        token = user.generate_auth_token(expiration=360000)
        redis_store.set(str(user.id), token)
        return ({'status': 'success', 'token': token}, 201)
Example #3
0
    def post(self):
        """
        Login in with a Facebook account if the user has existed
        Otherwises, create a new user with information from Facebook
        """
        args = fbUserParser.parse_args()
        fb_id = args['fbid']
        fb_token = args['fbtoken']
        if fb_id is None or fb_token is None:
            abort(400)

        # verify the user's facebook account using the facebook token
        fbuser_info = requests.get(
            'https://graph.facebook.com/me?access_token=%s' % fb_token).json()
        if not fbuser_info.get('id') or fb_id != fbuser_info['id']:
            abort(406)

        fb_email = args['fbemail']
        user = User.objects(email=fb_email).first()

        if user is None:
            user = User(email=fb_email, fb_id=fbuser_info['id'])
            user.save()

        token = user.generate_auth_token(expiration=360000)
        redis_store.set(str(user.id), token)
        return {'token': token}
Example #4
0
    def post(self):
        """
        Sign up with Facebook account and return a token
        """
        args = fbUserParser.parse_args()
        fb_id = args['fbid']
        fb_token = args['fbtoken']
        fb_email = args['fbemail']
        if fb_id is None or fb_token is None or fb_email is None:
            abort(400)

        # verify the user's facebook account using the facebook token
        fbuser_info = requests.get(
            'https://graph.facebook.com/me?access_token=%s' % fb_token).json()
        if not fbuser_info.get('id') or fb_id != fbuser_info['id']:
            abort(406)

        user = User(email=fb_email, fb_id=fb_id)
        try:
            user.save()
        except:
            return {'status': 'error', 'message': 'FBname has already existed'}

        token = user.generate_auth_token(expiration=360000)
        redis_store.set(str(user.id), token)
        return ({'status': 'success', 'token': token}, 201)
Example #5
0
    def post(self):
        """
        Login in the user and store the user id and token pair into redis
        """
        args = userParser.parse_args()
        email = args['email']
        password = args['password']
        if email is None or password is None:
            abort(400)

        user = User.objects(email=email).first()

        if not user or not user.verify_password(password):
            return {
                'status': 'error',
                'message': 'The email does not exist or password is wrong'
            }
        if not user.is_activated:
            return {
                'status': 'error',
                'message': 'The account has not been activated'
            }

        token = user.generate_auth_token(expiration=360000)
        redis_store.set(str(user.id), token)
        return {'token': token}
Example #6
0
    def post(self):
        """
        Login in with a Facebook account if the user has existed
        Otherwises, create a new user with information from Facebook
        """
        args = fbUserParser.parse_args()
        fb_id = args['fbid']
        fb_token = args['fbtoken']
        if fb_id is None or fb_token is None:
            abort(400)

        # verify the user's facebook account using the facebook token
        fbuser_info = requests.get(
            'https://graph.facebook.com/me?access_token=%s' % fb_token).json()
        if not fbuser_info.get('id') or fb_id != fbuser_info['id']:
            abort(406)

        fb_email = args['fbemail']
        user = User.objects(email=fb_email).first()

        if user is None:
            user = User(email=fb_email, fb_id=fbuser_info['id'])
            user.save()

        token = user.generate_auth_token(expiration=360000)
        redis_store.set(str(user.id), token)
        return {'token': token}
Example #7
0
 def get(self, user_id):
     """
     Renew the authorisation token by providing old token
     """
     user = User.objects(id=user_id).first()
     token = user.generate_auth_token(expiration=360000)
     redis_store.set(user_id, token)
     return {'token': token}
Example #8
0
 def get(self, user_id):
     """
     Renew the authorisation token by providing old token
     """
     user = User.objects(id=user_id).first()
     token = user.generate_auth_token(expiration=360000)
     redis_store.set(user_id, token)
     return {'token': token}
Example #9
0
    def post(self):
        args = userParser.parse_args()
        email = args['email']
        password = args['password']
        if email is None or password is None:
            abort(400)

        user = User.objects(email=email).first()

        if not user or not user.verify_password(password):
            return {'status': 'error', 'message':
                    'The email does not exist or password is wrong'}
        if not user.is_activated:
            return {'status': 'error', 'message':
                    'The account has not been activated'}

        token = user.generate_auth_token(expiration=360000)
        redis_store.set(str(user.id), token)
        return {'token': token}
Example #10
0
    def post(self):
        args = userParser.parse_args()
        email = args['email']
        password = args['password']
        if email is None or password is None:
            abort(400)
  
        user = User.objects(email=email).first()

        if not user or not user.verify_password(password):
            raise InvalidUsage('Email and password do not match')
        if not user.is_activated:
            raise InvalidUsage('Account not activated')

        profile = Profile.objects(user=user.id).first()

        rongToken = rongcloudToken(profile.id)
        token = user.generate_auth_token()
        redis_store.set(str(user.id), token)
        return {'token': token, 'rongToken' : rongToken}
Example #11
0
    def post(self):
        args = fbUserParser.parse_args()
        fb_id = args['fbid']
        fb_token = args['fbtoken']
        fb_email = args['fbemail']
        if fb_id is None or fb_token is None or fb_email is None:
            abort(400)    # missing arguments
        
        fbuser_info = requests.get('https://graph.facebook.com/me?access_token=%s' %fb_token).json()
        if not fbuser_info.get('id') or fb_id != fbuser_info['id']:
            abort(406)
        
        user = User(email=fb_email, fb_id=fb_id)
        try:
            user.save()
        except:
            return {'status': 'error', 'message': 'FBname has already existed'}

        token = user.generate_auth_token()
        redis_store.set(str(user.id), token)
        return ({'status': 'success', 'token': token}, 201)
Example #12
0
 def get(self, user_id):
     user = User.objects(id=user_id).first()
     token = user.generate_auth_token(expiration=360000)
     redis_store.set(user_id, token)
     return {'token': token}
Example #13
0
        if email is None or password is None:
            abort(400)    

        user = User(email=email)
        user.hash_password(password)
        profile = Profile(user=user)
        try:
            user.save()
            profile.save()
        except ValidationError, e:
            raise InvalidUsage(e.message)  
        except NotUniqueError, e:
            raise InvalidUsage(e.message)

        token = user.generate_auth_token()
        redis_store.set(str(user.id), token)
        send_activate_account_email(email,token)

        return ({'status': 'success', 'message': 'Please check your email to activate your account.'}, 201)


class LoginAPI(Resource):
    # renew token by using old valid token 
    @auth_required
    def get(self, user_id):
        user = User.objects(id=user_id).first()
        token = user.generate_auth_token()
        redis_store.set(user_id, token)
        return {'token': token}

    def post(self):