public RequestConfirmPhoneNumberRespond RequestConfirmPhoneNumber(string userId, string phoneNo)
 {
     var request = new RequestConfirmPhoneNumberRequest
     {
         PhoneNo = phoneNo,
         UserId = userId
     };
     var result = FacadeRepository.Instance.AccountFacade.RequestConfirmPhoneNumber(request);
     return result;
 }
 public void RequestConfirmPhoneNumber(RequestConfirmPhoneNumberRequest request, string verificationCode)
 {
     using (var dctx = new DailySoccer.DAC.EF.DailySoccerModelContainer())
     {
         var newData = new PhoneVerification
         {
             PhoneNumber = request.PhoneNo,
             UserId = request.UserId,
             VerificationCode = verificationCode
         };
         dctx.PhoneVerifications.Add(newData);
         dctx.SaveChanges();
     }
 }
示例#3
0
        public RequestConfirmPhoneNumberRespond RequestConfirmPhoneNumber(RequestConfirmPhoneNumberRequest request)
        {
            var invalidDataModel = new RequestConfirmPhoneNumberRespond { IsSuccessed = false };
            var isArgumentValid = request != null
                && !string.IsNullOrEmpty(request.UserId)
                && !string.IsNullOrEmpty(request.PhoneNo);
            if (!isArgumentValid) return invalidDataModel;

            request.PhoneNo = request.PhoneNo.Replace("-", string.Empty);
            if (request.PhoneNo.StartsWith("0", StringComparison.CurrentCultureIgnoreCase))
            {
                request.PhoneNo = string.Format("+66{0}", request.PhoneNo.Substring(1, request.PhoneNo.Length-1));
            }
            const int MinimumPhoneNumberRequired = 6;
            const int MaximumPhoneNumberRequired = 20;
            var isPhoneNumberValid = request.PhoneNo.Length >= MinimumPhoneNumberRequired && request.PhoneNo.Length <= MaximumPhoneNumberRequired;
            if (!isPhoneNumberValid) return invalidDataModel;

            var accountDac = FacadeRepository.Instance.AccountDataAccess;
            var selectedAccount = accountDac.GetAccountBySecrectCode(request.UserId);
            var isAccountValid = selectedAccount != null && string.IsNullOrEmpty(selectedAccount.VerifiedPhoneNumber);
            if (!isAccountValid) return invalidDataModel;

            const int RequiredVerificationDigits = 10;
            var verificationCode = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(0, RequiredVerificationDigits).ToUpper();
            accountDac.RequestConfirmPhoneNumber(request, verificationCode);
            FacadeRepository.Instance.PhoneVerificationFacade.SendMessage(request.PhoneNo, verificationCode);

            return new RequestConfirmPhoneNumberRespond
            {
                IsSuccessed = true,
                ForPhoneNumber = request.PhoneNo,
                VerificationCode = verificationCode
            };
        }