Beispiel #1
0
    def get(self, obj_id=None, user_id=None):

        mongo_connect()
        data = {}
        id = request.args.get('id')
        user_auth_id = request.args.get('user_auth_id')
        if id is None and user_auth_id is None:
            user_obj = CcUserAccount.objects.get.all()
            if user_obj:
                return Response(json.dumps(parse_mongodata(user_obj)),
                                mimetype='application/json')
            else:
                abort(404)

        if id:
            user_obj = CcUserAccount.objects.get(id=id)
            if user_obj:
                return Response(json.dumps(parse_mongodata(user_obj)),
                                mimetype='application/json')
                # resp={}
                # meta = {}
                # resp = {'data':user_obj,'meta':meta}
                # return self.response.custom_response("success",resp,201)

        if user_auth_id:
            user_obj = CcUserAccount.objects.get(user_auth_id=user_auth_id)
            if user_obj:
                return Response(json.dumps(parse_mongodata(user_obj)),
                                mimetype='application/json')

        abort(404)
Beispiel #2
0
def generate_otp(length, params):
    resp = {}
    # resp['user'] =
    resp['create_doc'] = True
    resp['otp_val'] = ''
    if not bool(params):
        return resp
    for key, value in params.items():
        if not value:
            return resp

    from api.models.Mongo_modal import CcUserOtp
    from api.models.configure import mongo_connect

    mongo_connect()
    params['cc_is_otp_used'] = False
    import random
    current_time = datetime.datetime.utcnow()

    try:
        payload_list = CcUserOtp.objects(**params).as_pymongo()
        # payload = [item.to_mongo() for item in payload_list ]
        for item in payload_list:
            if item["otp_expiration_time"] > current_time:
                resp['create_doc'] = False
                resp['otp_val'] = item["user_mobile_otp"]
                return resp
    except:
        pass

    lower = 10**(length - 1)
    upper = 10**length - 1
    resp['otp_val'] = random.randint(lower, upper)
    return resp
Beispiel #3
0
def forgot_password(**kwargs):
    data = dict(
        user=dict(username=kwargs['username'], ),
        otp_for_reset_password=generateOTP(),
        support_phone=config.SUPPORT_PHONE,
        contact_url=config.CONTACT_URL,
    )
    import pdb
    pdb.set_trace()
    mongo_connect()
    mongo_data = {}
    mongo_data['user_auth_id'] = kwargs['user_auth_id']
    mongo_data['user_mobile_number'] = kwargs['user_mobile_number']
    mongo_data['user_mobile_otp'] = data['otp_for_reset_password']
    mongo_data['cc_project_id'] = kwargs['cc_project_id']
    # import pdb
    # pdb.set_trace()
    try:
        mongo_obj = CcUserOtp(**mongo_data).save()
    except Exception as e:
        error = {"error": {"message": e._message, "status_code": 400}}
        return self.response.custom_response("error", error, 400)
    send_email_custom('*****@*****.**', data=data)
    #send_notification(client='Email', event='ResetPassword', receiver_type='EndUser', data=data)

    return dict(username=kwargs['username'])
Beispiel #4
0
    def post(self, **kwargs):
        mongo_connect()
        payload = request.json
        import pdb
        pdb.set_trace()
        account_data = {}
        account_data.update(
            {'user_auth_id': payload['data']['accounts']['object_id']})
        account_data.update({
            'cc_user_type_id':
            payload['data']['accounts']['object_account_id']
        })
        account_data.update({'user_account_email': "*****@*****.**"})
        account_data.update({'user_account_type': 1})
        account_data.update({'user_pin_code': 4110050})
        account_data.update({'created_by': 123})
        account_data.update({'updated_by': 13})
        account_data.update(
            {'cc_project_id': payload['meta']['cc_project_id']})
        account_data.update({
            'user_account_full_name':
            payload['data']['account_details']['first_name'] + " " +
            payload['data']['account_details']['last_name']
        })
        account_data.update(
            {'city_id': payload['data']['account_details']['city_id']})
        account_data.update({
            'user_account_street_address':
            payload['data']['account_details']['addresses']
        })
        account_data.update({
            'user_account_address_landmark':
            payload['data']['account_details']['landmark']
        })
        account_data.update(
            {'state_id': payload['data']['account_details']['state_id']})
        account_data.update({
            'user_account_mobile_no':
            payload['data']['account_details']['mobile_no']
        })
        account = CcUserAccount(**account_data)
        account.save()

        resp = {}
        meta = {
            "cc_project_id": payload['meta']['cc_project_id'],
            "src_type_id": payload['meta']['src_type_id'],
            "city_id": payload['data']['account_details']['city_id'],
        }
        data = {
            "Object_id": payload['data']['accounts']['object_id'],
            "Object_account_id":
            payload['data']['accounts']['object_account_id'],
            "City_id": payload['data']['account_details']['city_id'],
            "user_auth_token": 0
        }
        resp = {'data': data, 'meta': meta}
        return self.response.custom_response("success", resp, 201)
Beispiel #5
0
def verify_otp(params, otp_input):
    resp = {}
    # resp['user'] =
    resp['message'] = ''
    resp['status'] = False
    if not bool(params):
        resp['message'] = 'pass params'
        # resp['status'] = False
        return resp
    for key, value in params.items():
        if not value:
            resp['message'] = 'pass params values'
            # resp['status'] = False
            return resp

    from api.models.Mongo_modal import CcUserOtp
    from api.models.configure import mongo_connect

    mongo_connect()

    import random
    current_time = datetime.datetime.utcnow()
    # import pdb
    # pdb.set_trace()
    try:
        params['cc_is_otp_used'] = False
        otp_data = CcUserOtp.objects(**params).as_pymongo()
        for item in otp_data:
            if item["otp_expiration_time"] > current_time:
                if item["user_mobile_otp"] == otp_input:
                    update_otp_data = {}
                    update_otp_data['cc_is_otp_used'] = True
                    update_otp_data['updated_by'] = params['user_auth_id']
                    # update_otp_data['cc_is_otp_used'] = True
                    item.update(**update_otp_data)
                    resp['message'] = 'right otp'
                    resp['status'] = True
                    return resp

                else:
                    resp['message'] = 'otp not match'
                    return resp
            else:
                resp['message'] = 'otp expired'
                return resp
            # else:
        resp['message'] = 'otp not found'
        # resp['status'] = False
        return resp
        # payload = parse_mongodata(payload_list.to_mongo())
    except:
        resp['message'] = 'db error'
        # resp['status'] = False
        return resp
Beispiel #6
0
 def delete(self, **kwargs):
     mongo_connect()
     payload = request.json
     profile_data = {}
     profile_id = payload['data']['profiles']['object_id']
     user_obj = CcUserProfile.objects.get(id=profile_id).to_mongo()
     if user_obj is None:
         abort(404)
     else:
         #profile_data = payload['data']['profiles_details']
         user_obj['is_active'] = False
         user_obj.update(**user_obj)
Beispiel #7
0
 def put(self, **kwargs):
     mongo_connect()
     payload = request.json
     import pdb
     pdb.set_trace()
     profile_data = {}
     auth_id = payload['data']['profiles']['object_id']
     user_obj = CcUserProfile.objects.get(user_auth_id=auth_id)
     if user_obj is None:
         abort(404)
     else:
         profile_data = payload['data']['profiles_details']
         user_obj.update(**profile_data)
Beispiel #8
0
    def put(self, **kwargs):

        mongo_connect()
        payload = request.json
        import pdb
        pdb.set_trace()
        profile_data = {}
        auth_id = payload['data']['accounts']['object_id']
        profile_id = payload['data']['accounts']['object_account_id']
        account_obj = CcUserAccount.objects.get(user_auth_id=auth_id)
        profile_obj = CcUserProfile.objects.get(id=profile_id)
        if account_obj is None or profile_obj is None:
            abort(404)
        else:
            profile_data['user_account_full_name'] = payload['data'][
                'account_details']['first_name'] + " " + payload['data'][
                    'account_details']['last_name']
            profile_data['city_id'] = payload['data']['account_details'][
                'city_id']
            profile_data['user_account_street_address'] = payload['data'][
                'account_details']['addresses']
            profile_data['state_id'] = payload['data']['account_details'][
                'state_id']
            profile_data['user_pin_code'] = payload['data']['account_details'][
                'pin_code']
            profile_data['user_account_mobile_no'] = payload['data'][
                'account_details']['mobile_no']
            account_obj.update(**profile_data)
        resp = {}
        meta = {
            "cc_project_id": payload['meta']['cc_project_id'],
            "src_type_id": payload['meta']['src_type_id'],
            "city_id": payload['data']['account_details']['city_id'],
        }
        data = {
            "Object_id": payload['data']['accounts']['object_id'],
            "Object_account_id":
            payload['data']['accounts']['object_account_id'],
            "City_id": payload['data']['account_details']['city_id'],
            "user_auth_token": 0
        }
        resp = {'data': data, 'meta': meta}
        return self.response.custom_response("success", resp, 201)
Beispiel #9
0
    def get(self, **kwargs):
        mongo_connect()
        data = {}
        id = request.args.get('id')
        user_auth_id = request.args.get('user_auth_id')
        if id:
            user_obj = CcUserProfile.objects.get(id=id)
            if user_obj:
                return Response(json.dumps(parse_mongodata(user_obj)),
                                mimetype='application/json')
                # resp={}
                # meta = {}
                # resp = {'data':user_obj,'meta':meta}
                # return self.response.custom_response("success",resp,201)

        if user_auth_id:
            user_obj = CcUserProfile.objects.get(user_auth_id=user_auth_id)
            if user_obj:
                return Response(json.dumps(parse_mongodata(user_obj)),
                                mimetype='application/json')

        abort(404)
Beispiel #10
0
def get_customer_details(offset=None, **params_dict):
    resp = {}
    resp['is_error'] = 0
    resp['message'] = ''
    resp['data'] = []

    if not bool(params_dict):
        resp['is_error'] = 1
        resp['message'] = 'pass parameters'
        return resp
    for key, value in params_dict.items():
        if not value:
            resp['is_error'] = 1
            resp['message'] = "values can't be empty"
            return resp
        # else:
        #     if key == "user_auth_id"

    from api.models.Mongo_modal import CcUserProfile
    from api.models.configure import mongo_connect

    mongo_connect()

    try:
        payload_list = CcUserProfile.objects(**params_dict)
    except Exception as e:
        resp['is_error'] = 1
        resp['message'] = e
        return resp

    if offset:
        payload_list = payload_list[offset[0]:offset[1]]

    payload = [parse_mongodata(item.to_mongo()) for item in payload_list]
    resp['is_error'] = 0
    resp['message'] = "Found user"
    resp['data'] = payload
    return resp
Beispiel #11
0
    def post(self):

        error = {}

        try:
            payload = request.json

        except BadRequest as e:
            error = {
                "error": {
                    "message": "Please check meta or data is provided",
                    "status_code": 400
                }
            }
            return self.response.custom_response("error", error, 400)

        serialized_data, serialize_errors = self.serializer.load(payload)

        if serialize_errors:
            error = {
                "error": {
                    "message": serialize_errors,
                    "status_code": 400
                }
            }
            return self.response.custom_response("error", error, 400)

        from api.common.helper import get_customer_details, send_sms, generate_otp, send_email

        user_query = {}
        user_query['user_auth_id'] = serialized_data['data']['object_id']

        offset = None
        customer_details = get_customer_details(offset, **user_query)

        if customer_details['is_error']:
            error = {
                "error": {
                    "message": customer_details['message'],
                    "status_code": 400
                }
            }
            return self.response.custom_response("error", error, 400)

        otp_data = {
            "user_auth_id": serialized_data['data']['object_id'],
            "cc_project_id": serialized_data['meta']['cc_project_id'],
            "otp_generated_for": serialized_data['data']['otp_action']
        }

        otp = generate_otp(6, otp_data)

        if not otp['otp_val']:
            error = {
                "error": {
                    "message": "can't generate otp",
                    "status_code": 400
                }
            }
            return self.response.custom_response("error", error, 400)

        if otp['create_doc']:
            otp_creation_time = datetime.datetime.utcnow()

            otp_expiration_time = otp_creation_time + datetime.timedelta(
                minutes=10)

            from api.models.Mongo_modal import CcUserOtp
            from api.models.configure import mongo_connect

            mongo_connect()

            user_data = {}

            user_data['user_auth_id'] = serialized_data['data']['object_id']
            user_data['user_profile_id'] = str(
                customer_details['data'][0]['id'])
            user_data['user_mobile_number'] = customer_details['data'][0][
                'mobile_no']
            user_data['user_mobile_otp'] = otp['otp_val']
            user_data['otp_generated_for'] = serialized_data['data'][
                'otp_action']
            user_data['cc_project_id'] = serialized_data['meta'][
                'cc_project_id']
            user_data['cc_is_otp_used'] = False
            user_data['cc_user_type_id'] = customer_details['data'][0][
                'cc_user_type_id']
            user_data['otp_creation_time'] = otp_creation_time
            user_data['otp_expiration_time'] = otp_expiration_time
            user_data['is_active'] = True
            user_data['created_by'] = str(customer_details['data'][0]['id'])
            user_data['created_at'] = datetime.datetime.utcnow()
            user_data['updated_by'] = str(customer_details['data'][0]['id'])

            try:
                mongo_obj = CcUserOtp(**user_data).save()
            except Exception as e:
                error = {"error": {"message": e, "status_code": 400}}
                return self.response.custom_response("error", error, 400)

            mongo_insert_data = parse_mongodata(mongo_obj.to_mongo())

        # if not bool(mongo_insert_data):
        #     error = {"error":{"message":"Mongo Data not insereted in the Database", "status_code": 400}}
        #     return self.response.custom_response("error",error,400)

        # sms_type = email_type = '1'
        sms_email_details = {}
        sms_email_details['email_type'] = sms_email_details['sms_type'] = '1'
        sms_email_details['otp_value'] = otp['otp_val']
        send_sms = send_sms(customer_details['data'][0]['mobile_no'],
                            **sms_email_details)
        # send_email = send_email(customer_details['data'][0]['email'], **sms_email_details)

        if not send_email and not send_sms:
            # CcUserOtp(id=ObjectId(mongo_insert_data['id'])).delete()
            error = {
                "error": {
                    "message": "sms and email not send",
                    "status_code": 400
                }
            }
            return self.response.custom_response("error", error, 400)

        cc_project_id = serialized_data['meta']['cc_project_id']
        cc_src_type_id = serialized_data['meta']['cc_src_type_id']
        user_auth_token = serialized_data['meta']['user_auth_token']

        resp = {}
        meta = {
            "cc_project_id": cc_project_id,
            "cc_src_type_id": cc_src_type_id
        }
        data = {
            "object_id": serialized_data['data']['object_id'],
            "user_auth_token": user_auth_token,
            "response": "OTP sent",
            "otp_action": 1
        }
        resp = {'data': data, 'meta': meta}

        return self.response.custom_response("success", resp, 201)
Beispiel #12
0
    def post(self, **kwargs):

        sql_data = {}
        error = {}
        mongo_data = {}
        sql_data['created_at'] = datetime.datetime.utcnow()

        mongo_data['created_at'] = datetime.datetime.utcnow()
        mongo_data['updated_at'] = datetime.datetime.utcnow()

        sql_data['is_active'] = True
        mongo_data['is_active'] = True

        try:
            import json
            payload = request.json

        except BadRequest as e:
            error = {
                "error": {
                    "message": "Please check meta or data is provided",
                    "status_code": 400
                }
            }
            return self.response.custom_response("error", error, 400)
        serialized_data, serialize_errors = self.serializer.load(payload)

        if serialize_errors:
            error = {
                "error": {
                    "message": serialize_errors,
                    "status_code": 400
                }
            }
            return self.response.custom_response("error", error, 400)

        auth_insert_data = {}
        password_hashed = password_hash(
            serialized_data['data']['info']['password'])

        if not password_hashed['status']:
            error = {
                "error": {
                    "message": "password can't be hashed",
                    "status_code": 400
                }
            }
            return self.response.custom_response("error", error, 400)

        sql_data['username'] = serialized_data['data']['info']['username']
        sql_data['password'] = password_hashed['pass']
        sql_data['cc_login_type'] = 1
        sql_data['cc_project_id'] = serialized_data['meta']['cc_project_id']
        sql_data['cc_user_type_id'] = serialized_data['meta'][
            'cc_user_type_id']
        sql_data['created_by'] = 1
        sql_data['updated_by'] = 1

        try:
            from api.models.configure import mysql_session

            sql_obj = UserAuthModal(**sql_data)
            mysql_session.add(sql_obj)
            mysql_session.commit()
            auth_insert_data = sql_obj.to_dict()

        except SQLAlchemyError as exc:
            mysql_session.rollback()
            error = {
                "error": {
                    "message": exc.orig.args[1],
                    "status_code": 400
                }
            }
            return self.response.custom_response("error", error, 400)

        if not bool(auth_insert_data):
            mysql_session.rollback()
            error = {
                "error": {
                    "message": "Mysql Data not insereted in the Database",
                    "status_code": 400
                }
            }
            return self.response.custom_response("error", error, 400)

        mongo_connect()

        user_auth_id = auth_insert_data['id']

        mongo_data['first_name'] = serialized_data['data']['info'][
            'first_name']
        mongo_data['last_name'] = serialized_data['data']['info']['last_name']
        mongo_data['mobile_no'] = serialized_data['data']['info'][
            'phone_number']
        mongo_data['email'] = serialized_data['data']['info']['email_address']
        mongo_data['cc_src_type_id'] = serialized_data['meta'][
            'cc_src_type_id']
        mongo_data['city_id'] = serialized_data['data']['info']['city_id']
        mongo_data['cc_project_id'] = serialized_data['meta']['cc_project_id']
        mongo_data['cc_user_type_id'] = serialized_data['meta'][
            'cc_user_type_id']
        mongo_data['created_by'] = 1
        mongo_data['updated_by'] = 1
        mongo_data['user_auth_id'] = user_auth_id
        mongo_data['area_id'] = serialized_data['data']['info']['pincode']
        try:
            mongo_obj = CcUserProfile(**mongo_data).save()
        except Exception as e:
            mysql_session.delete(sql_obj)
            mysql_session.commit()
            error = {"error": {"message": e._message, "status_code": 400}}
            return self.response.custom_response("error", error, 400)

        mongo_insert_data = parse_mongodata(mongo_obj.to_mongo())

        if not bool(mongo_insert_data):
            error = {
                "error": {
                    "message": "Mongo Data not insereted in the Database",
                    "status_code": 400
                }
            }
            return self.response.custom_response("error", error, 400)

        sql_update_data = {}
        sql_update_data['object_id'] = mongo_insert_data['id']
        sql_update_data['updated_at'] = datetime.datetime.utcnow()

        try:
            get_user_obj = mysql_session.query(UserAuthModal).filter(
                UserAuthModal.id == user_auth_id).update(sql_update_data)
            mysql_session.commit()
            auth_update_data = sql_obj.to_dict()

        except SQLAlchemyError as exc:
            mysql_session.delete(sql_obj)
            mysql_session.commit()
            mongo_obj_delete = CcUserProfile.objects(
                id=ObjectId(mongo_insert_data['id'])).delete()
            # mysql_session.rollback()
            error = {
                "error": {
                    "message": exc.orig.args[1],
                    "status_code": 400
                }
            }
            return self.response.custom_response("error", error, 400)

        finally:
            mysql_session.close()

        if not bool(auth_update_data):
            error = {
                "error": {
                    "message": "Mongo Object Id not insereted in the Database",
                    "status_code": 400
                }
            }
            return self.response.custom_response("error", error, 400)

        # email_details = {}
        # email_details['email_type'] = '2'
        #email_details['otp_value'] = otp['otp_val']
        #send_sms = send_sms(customer_details['data'][0]['mobile_no'], **email_details)
        # send_email = send_email(customer_details['data'][0]['email'], **email_details)

        resp = {}
        meta = {
            "cc_project_id": sql_data['cc_project_id'],
            "cc_user_type_id": sql_data['cc_user_type_id']
        }
        data = {
            "city_id": mongo_data['city_id'],
            "object_id": mongo_insert_data['id'],
            "verified_status": {
                "is_email_verified": 0,
                "is_phone_verified": 0
            }
        }
        resp = {'data': data, 'meta': meta}
        return self.response.custom_response("success", resp, 201)
Beispiel #13
0
def verify_and_reset_password(**kwargs):
    otp = kwargs['otp']
    new_password = kwargs['new_password']
    response = GeneralResponses()
    mongo_connect()