Exemplo n.º 1
0
        public static async Task InitilazeRentoConstantData()
        {
            var typesResponse = await CallApi <List <BaseNameEntity> >("LookUp/List", "Type");

            if (typesResponse.ErrorCode == ErrorCode.Success && typesResponse.Data != null)
            {
                HttpContext.Current.Session["SYSTEM_TYPE"] = typesResponse.Data;
            }

            var subTypesResponse = await CallApi <List <BaseNameEntity <int> > >("LookUp/ListExternal", "SubType");

            if (subTypesResponse.ErrorCode == ErrorCode.Success && subTypesResponse.Data != null)
            {
                HttpContext.Current.Session["SYSTEM_SUB_TYPE"] = subTypesResponse.Data;
            }


            var countryResponse = await CallApi <List <BaseNameEntity> >("LookUp/List", "Country");

            if (countryResponse.ErrorCode == ErrorCode.Success && countryResponse.Data != null)
            {
                RentoCache.Set("SYSTEM_COUNTRY", countryResponse.Data);
            }

            var cityResponse = await CallApi <List <BaseNameEntity <int> > >("LookUp/ListExternal", "City");

            if (cityResponse.ErrorCode == ErrorCode.Success && cityResponse.Data != null)
            {
                RentoCache.Set("SYSTEM_CITY", cityResponse.Data);
            }
        }
Exemplo n.º 2
0
        public async Task <IHttpActionResult> ForgetPassword(RentoRequest <string> request)
        {
            Logger.Debug("ForgetPassword", request.Data);

            return(Ok(await TryCatchResponse(request, ValidateType.None, async(RentoResponse <string> response) =>
            {
                if (!ValidateRequirdField(request.Data))
                {
                    response.ErrorCode = ErrorCode.RequirdField; return;
                }
                var forgetPassword = await Database.AccountManager.SelectMobile(request.Data);
                if (forgetPassword != null)
                {
                    var code = StringHelper.GenerateRandomNumber(6);
                    RunActionAsync(() =>
                    {
                        SMSMessage.Send(forgetPassword.Mobile, code.ToString());
                    });
                    RentoCache.Set(FORGET_PASSWORD_KEY + forgetPassword.Token, new ForgetPasswordCacheObject()
                    {
                        Code = code,
                        UserId = forgetPassword.UserId
                    }, 1);
                    response.Data = forgetPassword.Token.ToString();
                }
            })));
        }
Exemplo n.º 3
0
        public async Task <IHttpActionResult> UpdateUserInfo(RentoRequest <User> request)
        {
            return(Ok(await TryCatchResponseBase(request, ValidateType.Pending, async(RentoResponse response) =>
            {
                var licence = request.Data.Licence;
                var logo = request.Data.Logo;
                var refarmeCard = request.Data.RefarmeCard;
                if (request.Data.Licence != null)
                {
                    if (!Rento.Helper.FileExtension.ScanImage(request.Data.Licence.Content))
                    {
                        response.ErrorCode = ErrorCode.InvalidImageFormat; return;
                    }
                    request.Data.Licence = new RentoImage();
                }
                if (request.Data.Logo != null)
                {
                    if (!Rento.Helper.FileExtension.ScanImage(request.Data.Logo.Content))
                    {
                        response.ErrorCode = ErrorCode.InvalidImageFormat; return;
                    }
                    request.Data.Logo = new RentoImage();
                }
                if (request.Data.RefarmeCard != null)
                {
                    if (!Rento.Helper.FileExtension.ScanImage(request.Data.RefarmeCard.Content))
                    {
                        response.ErrorCode = ErrorCode.InvalidImageFormat; return;
                    }
                    request.Data.RefarmeCard = new RentoImage();
                }

                Logger.Debug("User - UpdateUserInfo", request);

                request.Data.Licence = licence;
                request.Data.Logo = logo;
                request.Data.RefarmeCard = refarmeCard;

                if (!ValidateRequirdField(request.Data.CityId, request.Data.CountryId)
                    ||
                    ((UserType)UserSession.Type == UserType.Pending && (request.Data.Licence == null || request.Data.RefarmeCard == null))
                    ||
                    !ValidateRequirdField(request.Data.Mobile, request.Data.Name)
                    ||
                    !ValidateRequirdField(request.Data.Latitude, request.Data.Latitude)
                    )
                {
                    response.ErrorCode = ErrorCode.RequirdField; return;
                }
                request.Data.Mobile = SMSMessage.CheckMobileNumber(request.Data.Mobile);
                request.Data.Id = UserSession.Id;
                await Database.AccountManager.Update(request.Data);
                if ((UserType)UserSession.Type == UserType.Pending)
                {
                    UserSession.Type = (int)UserType.Active;
                }
                RentoCache.Set(request.Data.Id.ToString(), (byte)UserSession.Type);
            })));
        }
Exemplo n.º 4
0
 public async Task <IHttpActionResult> UpdateFlag(RentoRequest <UpdateUserFlagRequest> request)
 {
     Logger.Debug("User - UpdateFlag", request);
     return(Ok(await TryCatchResponseBase(request, ValidateType.Operation, async(RentoResponse response) =>
     {
         if (!ValidateRequirdField(request.Data.UserId))
         {
             response.ErrorCode = ErrorCode.RequirdField;
             return;
         }
         var userType = await UserManager.UpdateFlag(request.Data);
         RentoCache.Set(request.Data.UserId.ToString(), (byte)userType);
     })));
 }
Exemplo n.º 5
0
        private void SendVirificationCode(string mobileNumber, int userId, string token)
        {
            var code = StringHelper.GenerateRandomNumber(4);

            Logger.Debug("Send Code To Sign up", new { UserId = userId, Code = code, Mobile = mobileNumber });
            RunActionAsync(() =>
            {
                SMSMessage.Send(mobileNumber, string.Format("Your Verification Code is: {0}", code));
            });
            RentoCache.Set(VERIFICATION_KEY + token, new ForgetPasswordCacheObject()
            {
                Code   = code,
                UserId = userId
            }, 1);
        }
Exemplo n.º 6
0
        private async Task <UserSession> CheckToken(string token)
        {
            UserSession result = null;

            try
            {
                if (token.Contains('-'))
                {
                    result = RentoCache.Get <UserSession>(token);
                    if (result == null && !string.IsNullOrEmpty(token))
                    {
                        result = await Database.AccountManager.Login(token);

                        if (UserSession != null)
                        {
                            RentoCache.Set(token, UserSession);
                        }
                    }
                }
                else
                {
                    string[] tokenInfo = token.ToFlatString().Split(',');
                    byte     userType  = RentoCache.Get <byte>(tokenInfo[1]);
                    int      userId    = Convert.ToInt32(tokenInfo[1]);
                    if (userType == default(byte))
                    {
                        userType = await Database.AccountManager.GetUserType(userId);

                        RentoCache.Set(userId.ToString(), (byte)userType);
                        if (userType == 0)
                        {
                            return(null);
                        }
                    }
                    result = new UserSession()
                    {
                        Id       = userId,
                        Type     = userType,
                        Username = tokenInfo[0]
                    };
                }
            }
            catch
            {
                return(null);
            }
            return(result);
        }
Exemplo n.º 7
0
        public IHttpActionResult ResendCode(RentoRequest request)
        {
            Logger.Debug("ResendCode", request);

            var response = new RentoResponse(request);

            return(Ok(TryCatch(request, response, ValidateType.Pending,
                               async delegate()
            {
                var mobileNumber = await AccountManager.SelectMobile(UserSession.Id);
                if (!string.IsNullOrEmpty(mobileNumber))
                {
                    var lastCache = RentoCache.Get <int>(RESEND_CODE_KEY + mobileNumber);
                    if (lastCache == 0)
                    {
                        lastCache = 1;
                    }
                    if (lastCache > 3)
                    {
                        response.ErrorCode = ErrorCode.GeneralError;
                    }
                    else
                    {
                        RentoCache.Set(RESEND_CODE_KEY + mobileNumber, lastCache++);

                        RentoCache.Set(mobileNumber, 1);
                        var code = StringHelper.GenerateRandomNumber(4);
                        Logger.Debug("Send Code Resend", new { Code = code, Mobile = mobileNumber });
                        RunActionAsync(() =>
                        {
                            SMSMessage.Send(mobileNumber, string.Format("Your Verification Code is: {0}", code));
                        });
                        RentoCache.Set(VERIFICATION_KEY + request.Token, new ForgetPasswordCacheObject()
                        {
                            Code = code,
                            UserId = UserSession.Id
                        }, 1);
                    }
                }
            })));
        }
Exemplo n.º 8
0
 protected string GenerateToken(string userName, int userId, int userType)
 {
     RentoCache.Set(userId.ToString(), (byte)userType);
     return($"{userName},{userId},{DateTime.Now.AddHours(Constant.ADDITINAL_HOUT_TIME).Ticks}".ToEncreptedString());
 }