Esempio n. 1
0
        public void TestUserGoogleAuthentication()
        {
            var userID = new Random().Next(1, 3);
            var gakey = Utilities.GenerateOTPKey();

            var user = IoC.Resolve<IUserRepository>().FindById<User>(userID);
            var otp = Utilities.GenerateGoogleAuthOTP(gakey);
            var cmd = new UserOpenGoogleAuthentication(userID, gakey, otp);

            if (user.GoogleAuthentication != null)
            {
                var ex = Assert.Throws<CommandExecutionException>(delegate
                    {
                        this.commandBus.Send(cmd);
                    });

                Assert.Equal(ex.ErrorCode, (int)ErrorCode.GoogleAuthenticationIsSetted);
            }

            else
                Assert.DoesNotThrow(delegate
                {
                    this.commandBus.Send(cmd);
                });

            var savedUser = IoC.Resolve<IUserRepository>().FindById<User>(userID);

            Assert.NotNull(savedUser);
            Assert.NotNull(savedUser.GoogleAuthentication);
            Assert.Equal(savedUser.GoogleAuthentication.OTPSecret, gakey);
            Assert.False((savedUser.TwoFactorFlg & 2) == 2);
            Assert.False((savedUser.TwoFactorFlg & 8) == 8);
            Assert.Equal(savedUser.GoogleAuthentication.UserID, userID);
        }
Esempio n. 2
0
        public ActionResult BindGoogleAuthentication(string secretkey, string otpverify)
        {
            var result = FCJsonResult.CreateFailResult(this.Lang("Unable to verify Google Authentication code. Please try again."));
            try
            {
                var cmd = new UserOpenGoogleAuthentication(this.CurrentUser.UserID, secretkey, otpverify);
                this.CommandBus.Send(cmd);
                this.CurrentUser.TwoFactorFlg |= 11;

                result = FCJsonResult.CreateSuccessResult(this.Lang("Enable Google Authenticator successfully.Your Login2FA enabled by default."));
            }
            catch (CommandExecutionException ex)
            {
                Log.Error("Action BindGoogleAuthentication Error", ex);
            }
            return Json(result);
        }