public async Task MessageCaptchaSendAsync(MESSAGE_CAPTCHA_TYPE type, string mobile, int expiredTime) { try { // generate captcha code var captcha = CaptchaGenderator.GetCaptcha(); // call message captcha api // set cache cacheManager.Set("", new CaptchaMessageCacheData { Captcha = captcha, ExpiredTime = TimeSpan.FromMinutes(expiredTime), Mobile = mobile, Type = type }); } catch (WebException e) { //Logger.Error(e.Message, e); throw new UserFriendlyException(CAPTCHA_MANAGER_RETURN_CODE.SMS_SERVICE_NOT_AVAILABLE); } catch (Exception ex) { //Logger.Error(e.Message, ex); throw new UserFriendlyException(CAPTCHA_MANAGER_RETURN_CODE.MESSAGE_CAPTCHA_SEND_FAILED); } }
public Task MessageCaptchaValidateAsync(MESSAGE_CAPTCHA_TYPE captchaType, string mobile, string captcha) { // try get cache data var cache = cacheManager.Get <string>(""); if (cache == null) { throw new UserFriendlyException(CAPTCHA_MANAGER_RETURN_CODE.MESSAGE_CAPTCHA_IS_EXPIRED); } if (cache != captcha) { throw new UserFriendlyException(CAPTCHA_MANAGER_RETURN_CODE.MESSAGE_CAPTCHA_NOT_MATCHA); } return(Task.FromResult(0)); }
// public async Task ValidateMessageCaptchaAsync(ValidateMessageCaptchaAsyncRequest input) // { // await captchaManager.MessageCaptchaValidateAsync(input.CaptchaType, input.Mobile, input.Captcha); // } // public async Task LocalRegistrationAsync(LocalRegistrationAsyncRequest input) // { // await userAccountManager.LocalRegistrationAsync(input.Mobile, input.Password); // } // public async Task ValidateGraphicCaptchaAndSendMessageCaptchaAsync(ValidateGraphicCaptchaAndSendMessageCaptchaAsyncRequest input) // { // // try find user by mobile // var user = await userAccountManager.FindAsync(input.Mobile); // switch (input.CaptchaType) // { // case MESSAGE_CAPTCHA_TYPE.REGISTER: // // validate user mobile is exsit // if (user != null) // { // throw new UserFriendlyException(VALIDATE_GRAPHIC_CAPTCHA_AND_SEND_MESSAGE_CAPTCHA_RETURN_CODE.MOBILE_ALREADY_EXISTS); // } // // validate register graphic captcha // await captchaManager.GraphicCaptchaValidateAsync("",input.GraphicCaptcha); // // send register message captcha and it valid 10 minutes // await captchaManager.MessageCaptchaSendAsync(MESSAGE_CAPTCHA_TYPE.REGISTER, input.Mobile, 10); // break; // case MESSAGE_CAPTCHA_TYPE.RETRIEVE_PASSWORD: // // validate user mobile is exsit // if (user == null) // { // throw new UserFriendlyException(VALIDATE_GRAPHIC_CAPTCHA_AND_SEND_MESSAGE_CAPTCHA_RETURN_CODE.MOBILE_NOT_EXISTS); // } // // validate retrieve password graphic captcha // await captchaManager.GraphicCaptchaValidateAsync("", input.GraphicCaptcha); // // send retrieve password message captcha // await captchaManager.MessageCaptchaSendAsync(MESSAGE_CAPTCHA_TYPE.RETRIEVE_PASSWORD, input.Mobile, 10); // break; // default: // break; // } // } // public async Task RetrievePasswordAsync(RetrievePasswordAsyncRequest input) // { // // try find user by mobile // var user = await userAccountManager.FindAsync(input.Mobile); // } public Task <byte[]> GetGraphicCaptchaAsync(MESSAGE_CAPTCHA_TYPE type) { switch (type) { case MESSAGE_CAPTCHA_TYPE.REGISTER: // register graphic captcha return(Task.FromResult(GraphicCaptchaManager.GetBytes())); case MESSAGE_CAPTCHA_TYPE.RETRIEVE_PASSWORD: // reset password graphic captcha return(Task.FromResult(GraphicCaptchaManager.GetBytes())); default: break; } throw new UserFriendlyException(GETGRAPHIC_CAPTCHA_ASYNC_RETURN_CODE.INVALID_GRAPHIC_CAPTCHA); }
public Task MessageCaptchaResendAsync(MESSAGE_CAPTCHA_TYPE captcha, string mobile, int expiredTime) { throw new NotImplementedException(); }
public Task EmailCaptchaValidateAsync(MESSAGE_CAPTCHA_TYPE type, string email, string captha) { throw new NotImplementedException(); }
public Task EmailCaptchaResendAsync(MESSAGE_CAPTCHA_TYPE type, string mobile, int expiredTime) { throw new NotImplementedException(); }
public async Task <ActionResult> GetGraphicCaptchaAsync(MESSAGE_CAPTCHA_TYPE captcha_type) { return(File(await userAccountService.GetGraphicCaptchaAsync(captcha_type), @"image/jpeg")); }
public Task <CaptchaMessageCacheData> GetCaptchaMessageCacheDataAsync(MESSAGE_CAPTCHA_TYPE captchaType, string mobile, string captcha) { var cache = cacheManager.Get <CaptchaMessageCacheData>($"Captcha: Message:{mobile}"); return(Task.FromResult(cache)); }