Example #1
0
 public async Task <IHttpActionResult> Verification(RentoRequest <Verification> request)
 {
     Logger.Debug("Verification", request);
     return(Ok(await TryCatchResponseBase(request, ValidateType.Pending, async(RentoResponse response) =>
     {
         if (!ValidateRequirdField(request.Data.Code))
         {
             response.ErrorCode = ErrorCode.RequirdField;
             return;
         }
         ;
         var cacheReponse = RentoCache.Get <ForgetPasswordCacheObject>(VERIFICATION_KEY + request.Token);
         if (cacheReponse != null)
         {
             if (request.Data.Code.Equals(cacheReponse.Code))
             {
                 await AccountManager.Verify(cacheReponse.UserId);
                 UserSession.Type = (int)UserType.Customer_Active;
                 GenerateToken(UserSession);
             }
             else
             {
                 response.ErrorCode = ErrorCode.InvalidCode;
             }
         }
         else
         {
             response.ErrorCode = ErrorCode.UserDoesNotExist;
         }
     })));
 }
Example #2
0
 public async Task <IHttpActionResult> ResetPassword(RentoRequest <ResetPassword> request)
 {
     Logger.Debug("ResetPassword", request.Data);
     return(Ok(await TryCatchResponseBase(request, ValidateType.None, async(RentoResponse response) =>
     {
         if (!ValidateRequirdField(request.Data.Code) || !ValidateRequirdField(request.Data.NewPassword))
         {
             response.ErrorCode = ErrorCode.RequirdField; return;
         }
         var cacheReponse = RentoCache.Get <ForgetPasswordCacheObject>(FORGET_PASSWORD_KEY + request.Token);
         if (cacheReponse != null)
         {
             if (request.Data.Code.Equals(cacheReponse.Code))
             {
                 await Database.AccountManager.ResetPassword(cacheReponse.UserId, request.Data.NewPassword);
             }
             else
             {
                 response.ErrorCode = ErrorCode.InvalidCode;
             }
         }
         else
         {
             response.ErrorCode = ErrorCode.UserDoesNotExist;
         }
     })));
 }
Example #3
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);
        }
Example #4
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);
                    }
                }
            })));
        }