public ActionResult BindSMSAuthentication(string mobile, string otpverify) { var result = FCJsonResult.CreateFailResult(this.Lang("Unknow Exception,Please refresh the page and try again")); try { if (Session["BindSMSSecretCode"] != null) { var sms_otpkey = Session["BindSMSSecretCode"].ToString(); var cmd = new UserSetMobile(this.CurrentUser.UserID, mobile, sms_otpkey, otpverify); this.CommandBus.Send(cmd); this.CurrentUser.TwoFactorFlg |= 20; this.CurrentUser.Mobile = mobile; result = FCJsonResult.CreateSuccessResult(this.Lang("Disable Sms Authenticator successfully.")); } } catch (CommandExecutionException ex) { if (ex.ErrorCode == (int)ErrorCode.SMSPasswordError) result = FCJsonResult.CreateFailResult(this.Lang("Unable to update your mobile. Your Sms Authenticator code error.")); if (ex.ErrorCode == (int)ErrorCode.MobileHasSet) result = FCJsonResult.CreateFailResult(this.Lang("Your Mobile set yet,don't need set again.")); else Log.Error("Action bindSMSAuthentication Error", ex); } return Json(result); }
public void TestUserSMSAuthentication() { var userID = new Random().Next(1, 10); var mobile = "1399999999"; var smskey = Utilities.GenerateOTPKey(); var smsCounter = 0; var cmd = new UserSetMobile(userID, mobile, smskey, Utilities.GenerateSmsOTP(smskey, 1)); Assert.DoesNotThrow(delegate { this.commandBus.Send(cmd); }); var savedUser = IoC.Resolve<IUserRepository>().FindById<User>(userID); Assert.NotNull(savedUser); Assert.NotNull(savedUser.SmsAuthentication); Assert.Equal(savedUser.SmsAuthentication.OTPSecret, smskey); Assert.Equal(savedUser.SmsAuthentication.SmsCounter, smsCounter); Assert.False((savedUser.TwoFactorFlg & 4) == 4); Assert.False((savedUser.TwoFactorFlg & 16) == 16); Assert.Equal(savedUser.SmsAuthentication.UserID, userID); }