Example #1
0
async def verify_otp(app, otp_email, email,  otp_mobile, phone_number):

    otp_mobile_db = await accounts_query.find_mobile_otp(
                        app, phone_number)

    otp_email_db = await accounts_query.find_email_otp(
                        app, email)

    if not otp_mobile_db:
        raise errors.CustomError("No mobile otp exists")

    if not otp_email_db:
        raise errors.CustomError("No Email otp exists")

    #if not otp_email["otp_verified"]:
    #    raise errors.CustomError("This account has already been verified")


    if otp_mobile != otp_mobile_db["mobile_otp"]:
        logging.info(f"OTP_MOBILE <{otp_mobile}> OTP_MOBILE_DB <{otp_mobile_db}>")
        raise errors.CustomError("OTP received is incorrect for phone_number")
    logging.info("Otp for mobile has been verified")


    if otp_email != otp_email_db["email_otp"]:
        raise errors.CustomError("OTP received is incorrect for email")
    logging.info("otp for email has been verified")


    if otp_mobile_db["validity"] < now_time_stamp():
        raise errors.CustomError("Validity of OTP expired, please generate otp again")
    #await accounts_query.account_verified(app, email, phone_number)

    return
Example #2
0
async def register_user(request):
    """
    """
    required_fields = ["first_name", "last_name",
        "email", "password", "phone_number", "pancard"]

    validate_fields(required_fields, request.json)

    db_user = await accounts_query.find_on_key(request.app, "email", request.json["email"])

    if db_user:
        raise errors.CustomError("This email id has already been registered")

    if await accounts_query.find_on_key(request.app, "phone_number", request.json["phone_number"]):
        raise errors.CustomError("This phone_number has already been registered")

    required_pattern = re.compile('(?=.{6,})(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[@#$%^&*()])')
    if not required_pattern.match(request.json["password"]) or \
                        len(request.json["password"]) <= 8:
            raise errors.PasswordStrengthError()


    usr = await submit_user_account(request.app, pancard=request.json["pancard"], phone_number=request.json["phone_number"],
                        email=request.json["email"], role="USER",
                         password=request.json["password"], first_name=request.json["first_name"],
                        last_name=request.json["last_name"])

    return response.json(
            {
            'error': False,
            'success': True,
            "data": usr,
            })
Example #3
0
async def get_otp(request):
    required_fields = ["email", "phone_number"]
    validate_fields(required_fields, request.json)
    if len(str(request.json["phone_number"])) != 10:
        raise errors.CustomError("Incoreect length of Phone number")

    account_db = await accounts_query.find_user(request.app, request.json["phone_number"],
                        request.json["email"])


    validity = revoke_time_stamp(days=0, hours=2, minutes=0)
    logging.info(account_db)
    await ses_email(request.app, request.json["email"], account_db["user_id"],
                    validity, "Recovery OTP from Remedium", recovery=True)

    await send_message(request.app, account_db["user_id"],
                account_db["first_name"]+" " +account_db["last_name"] ,
                    request.json["phone_number"], validity)

    return response.json(
               {
                'error': False,
                'success': True,
                'message': "Please check your Email and Phone number for OTP",
                })
Example #4
0
async def get_address(request):
    """
    """


    if not address:
        raise errors.CustomError("address is required")

    instance = await resolve_address.ResolveAddress(address, request.app.config.REST_API_URL)

    if not instance.data:
        raise errors.ApiInternalError(f"State is not present on the blockchain for {address}")
    return response.json(
            {
            'error': False,
            'success': True,
            'message': f"{instance.type} type found",
            "data": instance.data,
            })
async def submit_user_account(app, pancard=None, phone_number=None, email=None, role=None, \
                     password=None, first_name=None, last_name=None):
    """
    org_name is by default None for the user
    """
    if role != "USER":
        raise errors.CustomError("Roel required is USER")

    user = await route_utils.new_user_account(app,
                                              pancard=pancard,
                                              phone_number=phone_number,
                                              email=email,
                                              role=role,
                                              first_name=first_name,
                                              last_name=last_name)
    ##no9w the create account address and signer will be the user himself

    user_mnemonic, user_account = await route_utils.set_password(
        app, account=user, password=password)


    master_pub, master_priv, zero_pub, zero_priv = await \
                remote_calls.from_mnemonic(app.config.GOAPI_URL, user_mnemonic)

    acc_signer = create_signer(zero_priv)
    ##hashing gst number and tan number if present

    ##import from ledger.account import float_account, other then create_asset_idxs
    ## wil be emprty for the float_account, if we push empty list on blockchain
    ##it wil hsow an error, its better to not to send them at the first place
    find_hash = lambda x: hashlib.sha512(x.encode()).hexdigest() if x else None

    transaction_data = {
        "config": app.config,
        "txn_key": acc_signer,
        "batch_key": app.config.SIGNER,
        "first_name": first_name,
        "last_name": last_name,
        "user_id": user_account["user_id"],
        "pancard": find_hash(pancard),
        "phone_number": find_hash(phone_number),
        "email": find_hash(email),
        "time": int(time.time()),
        "indian_time": route_utils.indian_time_stamp(),
        "role": "USER",
        "deactivate": False,
        "deactivate_on": None,
    }

    transaction_ids, batch_id = await __send_user_account(**transaction_data)

    logging.info(batch_id)
    if batch_id:
        ##if successful, insert this user in pending_users table
        user_account.update({
            "time": transaction_data["time"],
            "indian_time": transaction_data["indian_time"],
            "transaction_id": transaction_ids[0],
            "batch_id": batch_id,
            "role": "USER",
            "pancard": transaction_data["pancard"],
        })

        logging.debug(user_account)
        await accounts_query.insert_account(app, user_account)

        ##update user pending_user with claim, claim_by , claimed_on keys
    return user_account