public void SetUp()
 {
     _collector = Substitute.For<IItemCollector>();
     _scheduler = Substitute.For<IScheduler>();
     _loginModel = Substitute.For<ILoginModel>();
     _uut = new ScheduledShoppingListModel(_collector, _scheduler, _loginModel);
 }
 public RuleResult IsAuthenticated(ILoginModel model)
 {
     user user = CurrentUser.CurrentClient = GetFirstUser(model);
     return user == null
                ? RuleResult.Fail
                : RuleResult.Success;
 }
Ejemplo n.º 3
0
        public LoginPresenter(ILoginView view)
        {
            loginView = view;
            loginModel = new LoginModel();

            loginView.Login += LoginView_Login;
        }
 public void SetUp()
 {
     _model = Substitute.For<ILoginModel>();
     _messageService = Substitute.For<IMessageBoxService>();
     _wos = Substitute.For<IWindowOpeningService>();
     _uut = new LoginViewModel(_model, _messageService, _wos);
 }
 private user GetFirstUser(ILoginModel model)
 {
     string pass = Encryptor.Encrypt(model.PassWord);
     return _userRepository.Query()
         .FirstOrDefault(us => us.Name == model.Login
                               && us.Password == pass);
 }
Ejemplo n.º 6
0
        public static bool Login(string userName, string password)
        {
            LoginModel = loginManager.Login(userName, password);

            PublishAuthenticationEvent(LoginModel);

            return(loginManager.IsLogin);
        }
Ejemplo n.º 7
0
        public LoginPresenter(ILoginView loginView, ILoginModel loginModel, ISession session)
        {
            _session    = session;
            _loginView  = loginView;
            _loginModel = loginModel;

            _loginView.LoginClicked  += LoginView_LoginClicked;
            _loginView.CancelClicked += LoginView_CancelClicked;
        }
Ejemplo n.º 8
0
 public StartViewModel(ILoginModel loginBack)
 {
     _loginBack           = loginBack;
     SavedUsers           = new ObservableCollection <TokenViewModel>();
     NewLoginButton_Click = new DelegateCommand(
         SwitchViewModels,
         () => LoginAllowed
         );
 }
Ejemplo n.º 9
0
 public LoginViewModel(ILoginModel model, IToastService toastService, ILocalizationService localizationService)
 {
     IsLoginPanelShow        = true;
     IsRegistrationPanelShow = false;
     IsLoginProgressShow     = false;
     _model               = model;
     _toastService        = toastService;
     _localizationService = localizationService;
     Currencies           = new ObservableCollection <Currency>();
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Sets up the foodplan model with constructorinjection of all its properties
 /// </summary>
 /// <param name="foodplanCollector"></param>
 /// <param name="shoppingListModel"></param>
 /// <param name="recipeListModel"></param>
 /// <param name="loginModel"></param>
 /// <param name="msgBoxService"></param>
 public FoodplanModel(IFoodplanCollector foodplanCollector, IShoppingListModel shoppingListModel,
                      IRecipeListModel recipeListModel, ILoginModel loginModel, IMessageBoxService msgBoxService)
 {
     _foodplanCollector = foodplanCollector;
     _shoppingListModel = shoppingListModel;
     _recipeListModel   = recipeListModel;
     _loginModel        = loginModel;
     _msgBoxService     = msgBoxService;
     _foodPlan          = new Foodplan();
 }
Ejemplo n.º 11
0
        /// <summary>
        /// Sets up the foodplan model with constructorinjection of all its properties
        /// </summary>
        /// <param name="foodplanCollector"></param>
        /// <param name="shoppingListModel"></param>
        /// <param name="recipeListModel"></param>
        /// <param name="loginModel"></param>
        /// <param name="msgBoxService"></param>
        public FoodplanModel(IFoodplanCollector foodplanCollector, IShoppingListModel shoppingListModel,
		IRecipeListModel recipeListModel, ILoginModel loginModel, IMessageBoxService msgBoxService)
        {
            _foodplanCollector = foodplanCollector;
            _shoppingListModel = shoppingListModel;
            _recipeListModel = recipeListModel;
			_loginModel = loginModel;
            _msgBoxService = msgBoxService;
            _foodPlan = new Foodplan();
		}
Ejemplo n.º 12
0
        public void SetUp()
        {
            //Setup mocks
            _collector      = Substitute.For <IUserCollector>();
            _messageService = Substitute.For <IMessageBoxService>();
            _wos            = Substitute.For <IWindowOpeningService>();

            //Setup reals
            _model = new LoginModel(_collector);
            _sut   = new LoginViewModel(_model, _messageService, _wos);
        }
Ejemplo n.º 13
0
        public void SetUp()
        {
            //Setup mocks
            _collector = Substitute.For<IUserCollector>();
            _messageService = Substitute.For<IMessageBoxService>();
            _wos = Substitute.For<IWindowOpeningService>();

            //Setup reals
            _model = new LoginModel(_collector);
            _sut = new LoginViewModel(_model, _messageService, _wos);
        }
Ejemplo n.º 14
0
        public LoginViewModel(ILoginModel loginBack)
        {
            _loginBack = loginBack;

            LoginButton_Click = new DelegateCommand <object>(
                AttemptLogin,
                o => !string.IsNullOrEmpty(Username) && !LoginInProgress && ServerSet == ServerState.Connected
                );
            Server_Connect = new DelegateCommand(
                AttemptConnection,
                () => !string.IsNullOrEmpty(ServerUrl) && ServerSet != ServerState.Connecting);
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Sets up the LoginViewModel using constructor injection
        /// </summary>
        /// <param name="model"></param>
        /// <param name="messageService"></param>
        /// <param name="wos"></param>
        public LoginViewModel(ILoginModel model, IMessageBoxService messageService, IWindowOpeningService wos)
        {
            if (model == null) throw new ArgumentNullException();
            if (messageService == null) throw new ArgumentNullException();
            if (wos == null) throw new ArgumentNullException();

            _model = model;
            _messageService = messageService;
            _wos = wos;
            UserName = "";
            Password = "";
        }
        public void Setup()
        {
            _foodplanCollector = Substitute.For <IFoodplanCollector>();
            _shoppingListModel = Substitute.For <IShoppingListModel>();
            _recipeListModel   = Substitute.For <IRecipeListModel>();
            _loginModel        = Substitute.For <ILoginModel>();
            _msgBoxService     = Substitute.For <IMessageBoxService>();

            _uut          = new FoodplanModel(_foodplanCollector, _shoppingListModel, _recipeListModel, _loginModel, _msgBoxService);
            _uut.Foodplan = new Foodplan()
            {
                RecipeList = new List <Tuple <Recipe, DateTime> >()
            };
        }
        /// <summary>
        /// Sets up the ScheduledShoppingListModel with constructorinjection
        /// </summary>
        /// <param name="itemCollector"></param>
        /// <param name="scheduler"></param>
        /// <param name="loginModel"></param>
        public ScheduledShoppingListModel(IItemCollector itemCollector, IScheduler scheduler, ILoginModel loginModel)
        {
            if (itemCollector == null) throw new ArgumentNullException();
            if (scheduler == null) throw new ArgumentNullException();

            _shoppingList = new List<Item>();
            _itemCollector = itemCollector;
            _scheduler = scheduler;
            _loginModel = loginModel;
            UpdateShoppingList();

            _scheduler.Tick += UpdateShoppingList;
            _scheduler.Start();
        }
        private void OnAuthenticated(ILoginModel loginModel)
        {
            if (loginModel == null || string.IsNullOrEmpty(loginModel.Token))
            {
                GroupItems = null;
            }
            else
            {
                GroupItems = _menuDataService.GetMenus();
            }

            //Publish the authorized feature retrieved event.
            _eventAggregator.GetEvent <AuthorizedFeatureRetrievedEvent>().Publish(GroupItems);
        }
Ejemplo n.º 19
0
        public UserViewModel(ILoginModel loginBack, IRoomModel roomBack)
        {
            _roomBack  = roomBack;
            _loginBack = loginBack;

            LogoutButton_Clicked = new DelegateCommand(Logout, () => LogoutStatus == "Logout");
            Message_Sent         = new DelegateCommand(SendNewMessage, () => !string.IsNullOrWhiteSpace(SendMessageText) && LogoutStatus == "Logout");
            NewLine_Added        = new DelegateCommand(() => { SendMessageText += "\r\n"; });
            Invites         = new ObservableCollection <InviteViewModel>();
            NewJoin_Clicked = new DelegateCommand(JoinNewRoom, () => !string.IsNullOrEmpty(RoomToJoin));

            _roomBack.RoomSyncCompleted += OnRoomReady;
            _roomBack.NewInvite         += OnNewInvite;
            _roomBack.RoomJoined        += OnRoomJoined;
            _loginBack.LogoutCompleted  += OnLogoutAttempted;
        }
Ejemplo n.º 20
0
        public void SetUp()
        {
            //Setup mocks
            _userCollector = Substitute.For <IUserCollector>();
            _userCollector.GetShoppinglistId("").ReturnsForAnyArgs(5);
            _itemCollector = Substitute.For <IItemCollector>();

            //Setup reals
            _scheduler         = new TimerScheduler(2);
            _loginModel        = new LoginModel(_userCollector);
            _shoppingListModel = new ScheduledShoppingListModel(_itemCollector, _scheduler, _loginModel);
            _sut = new ShoppingListViewModel(_shoppingListModel);

            //Login with Henrik
            _userCollector.DoesUserExist("", "").ReturnsForAnyArgs(true);
            _loginModel.Login("Henrik", "secret");
        }
        public void SetUp()
        {
            //Setup mocks
            _userCollector = Substitute.For<IUserCollector>();
            _userCollector.GetShoppinglistId("").ReturnsForAnyArgs(5);
            _itemCollector = Substitute.For<IItemCollector>();

            //Setup reals
            _scheduler = new TimerScheduler(2);
            _loginModel = new LoginModel(_userCollector);
            _shoppingListModel = new ScheduledShoppingListModel(_itemCollector, _scheduler, _loginModel);
            _sut = new ShoppingListViewModel(_shoppingListModel);

            //Login with Henrik
            _userCollector.DoesUserExist("", "").ReturnsForAnyArgs(true);
            _loginModel.Login("Henrik", "secret");
        }
Ejemplo n.º 22
0
 public bool IsAdmin(ILoginModel loginModel)
 {
     return((RoleType)_context.ExecuteScalar <int>(@"
             SELECT
                 CustomerRoleId
             FROM
                 Customers
             WHERE
                 Email            = @email
             AND
                 CustomerPassword = @password
         ", new
     {
         email = loginModel.Login,
         password = ToMd5(loginModel.Password)
     }) == RoleType.Admin);
 }
Ejemplo n.º 23
0
 /// <summary>
 /// Sets upp all the ViewModels and Models
 /// </summary>
 public ViewModelLocator()
 {
     _messageBoxService = new MessageBoxService();
     _loginModel        = new LoginModel(new UserHttpCollector(5));
     _foodplanCollector = new FoodplanHttpCollector();
     _loginViewModel    = new LoginViewModel(_loginModel, _messageBoxService, new WindowOpeningService());
     _recipeListModel   = new RecipeListModel(new RecipeHTTPCollector());
     _shoppingListModel = new ScheduledShoppingListModel
                              (new ItemHttpCollector(), new TimerScheduler(60), _loginModel);
     _shoppingListViewModel = new ShoppingListViewModel(_shoppingListModel);
     _foodplanModel         = new FoodplanModel
                                  (_foodplanCollector, _shoppingListModel, _recipeListModel, _loginModel, _messageBoxService);
     _recipeViewModel          = new RecipeListViewModel(_recipeListModel, 300, _foodplanModel, _messageBoxService);
     _addRecipeWindowViewModel = new AddRecipeWindowViewModel(_recipeListModel, new DialogImageChooser());
     _foodplanViewModel        = new FoodplanViewModel(_foodplanModel);
     _mwmvvm = new MainWindowViewModel();
 }
Ejemplo n.º 24
0
        public async Task <IActionResult> Auth(LoginDTO model)
        {
            ILoginModel loginModel = ModelManager.Login;

            Mapper.Map <LoginDTO, ILoginModel>(model, loginModel);

            bool isAuthenticated = await ServiceManager.LoginService.CheckLogin(loginModel);

            string token = string.Empty;

            if (isAuthenticated)
            {
                token = JwtTokenhelper.Token(AppSettings.Secret, loginModel);
            }

            return(Ok(new { token }));
        }
Ejemplo n.º 25
0
        public static string Token(string secret, ILoginModel loginModel)
        {
            var tokenHandler    = new JwtSecurityTokenHandler();
            var key             = Encoding.ASCII.GetBytes(secret);
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject = new ClaimsIdentity(new Claim[]
                {
                    new Claim(ClaimTypes.Name, loginModel.Username.ToString()),
                    new Claim(ClaimTypes.UserData, loginModel.UserId.ToString())
                }),
                Expires            = DateTime.UtcNow.AddDays(1),
                SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
            };
            var token = tokenHandler.CreateToken(tokenDescriptor);

            return(tokenHandler.WriteToken(token));
        }
        /// <summary>
        /// Sets up the ScheduledShoppingListModel with constructorinjection
        /// </summary>
        /// <param name="itemCollector"></param>
        /// <param name="scheduler"></param>
        /// <param name="loginModel"></param>
        public ScheduledShoppingListModel(IItemCollector itemCollector, IScheduler scheduler, ILoginModel loginModel)
        {
            if (itemCollector == null)
            {
                throw new ArgumentNullException();
            }
            if (scheduler == null)
            {
                throw new ArgumentNullException();
            }

            _shoppingList  = new List <Item>();
            _itemCollector = itemCollector;
            _scheduler     = scheduler;
            _loginModel    = loginModel;
            UpdateShoppingList();

            _scheduler.Tick += UpdateShoppingList;
            _scheduler.Start();
        }
Ejemplo n.º 27
0
        public IAuthResult Login(ILoginModel model)
        {
            var result = new AuthResult
            {
                Message = Constants.MessageLoginFailUnknow,
                Success = false
            };

            UserService = Container.Resolve <IUserService>();
            var user = UserService.GetByLoginPassword(model.Login.ToLower(), model.Password);

            if (user != null)
            {
                result.Success = true;
                result.Message = Constants.MessageLoginSuccess;
                result.Login   = user.Login;
                result.UserID  = user.Id.ToString();
            }

            return(result);
        }
Ejemplo n.º 28
0
        public void Setup()
        {
            //Setup mocks
            _foodplanCollector = Substitute.For <IFoodplanCollector>();
            _itemCollector     = Substitute.For <IItemCollector>();
            _userCollector     = Substitute.For <IUserCollector>();
            _recipeCollector   = Substitute.For <IRecipeCollector>();

            //Setup reals
            _loginModel        = new LoginModel(_userCollector);
            _shoppingListModel = new ScheduledShoppingListModel
                                     (_itemCollector, new TimerScheduler(60), _loginModel);
            _recipeListModel = new RecipeListModel(_recipeCollector);

            // Uut
            _uut          = new FoodplanModel(_foodplanCollector, _shoppingListModel, _recipeListModel, _loginModel);
            _uut.Foodplan = new Foodplan()
            {
                RecipeList = new List <Tuple <Recipe, DateTime> >()
            };
        }
Ejemplo n.º 29
0
        /// <summary>
        /// Sets up the LoginViewModel using constructor injection
        /// </summary>
        /// <param name="model"></param>
        /// <param name="messageService"></param>
        /// <param name="wos"></param>
        public LoginViewModel(ILoginModel model, IMessageBoxService messageService, IWindowOpeningService wos)
        {
            if (model == null)
            {
                throw new ArgumentNullException();
            }
            if (messageService == null)
            {
                throw new ArgumentNullException();
            }
            if (wos == null)
            {
                throw new ArgumentNullException();
            }

            _model          = model;
            _messageService = messageService;
            _wos            = wos;
            UserName        = "";
            Password        = "";
        }
Ejemplo n.º 30
0
        public void SetUp()
        {
            _recipeSizeWidth = 220;
            //Setup mocks
            _foodplanCollector = Substitute.For<IFoodplanCollector>();
            _recipeCollector = Substitute.For<IRecipeCollector>();
            _msgService = Substitute.For<IMessageBoxService>();
            _itemCollector = Substitute.For<IItemCollector>();
            _userCollector = Substitute.For<IUserCollector>();
            _shoppingListModel = Substitute.For<IShoppingListModel>();

            //Setup reals
            _loginModel = new LoginModel(_userCollector);
            _recipeListModel = new RecipeListModel(_recipeCollector);
            _foodplanModel = new FoodplanModel(_foodplanCollector, _shoppingListModel, _recipeListModel, _loginModel, _msgService);
            _foodplanModel.Foodplan.RecipeList = new List<Tuple<Recipe, DateTime>>();
            _sut = new RecipeListViewModel(_recipeListModel, _recipeSizeWidth, _foodplanModel, _msgService);

            //Login with Henrik
            _userCollector.DoesUserExist("", "").ReturnsForAnyArgs(true);
            _loginModel.Login("Henrik", "secret");
        }
        public async Task <LoginResult> LogIn(ILoginModel model)
        {
            var user        = _unitOfWork.UserQueries.GetByEmailWithPermissions(model.Email);
            var loginResult = _userService.Login(user, model.Password, LoginTypes.Default.ToInt());

            if (!loginResult.Successful)
            {
                return(loginResult);
            }

            // Identify login by session guid rather than email, because session guid tells us everything (email, tenant, session) and can't be fabricated
            var permissions = string.Join(',', user.Permissions.Select(x => x.PermissionTypeId));
            var claims      = new List <Claim>
            {
                new Claim(ClaimTypes.NameIdentifier, loginResult.SessionGuid),
                new Claim(ClaimTypes.Email, user.Email),
                new Claim(ClaimTypes.Name, user.Email),
                new Claim(CustomClaimTypes.UserId, user.Id.ToString()),
                new Claim(CustomClaimTypes.TenantId, user.TenantId.ToString()),
                new Claim(CustomClaimTypes.Permissions, permissions),
            };

            // authentication successful so generate jwt token
            var key             = Encoding.ASCII.GetBytes(_appSettings.JwtSecret);
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject            = new ClaimsIdentity(claims, JwtBearerDefaults.AuthenticationScheme),
                Expires            = DateTime.UtcNow.AddDays(1),
                SigningCredentials = new SigningCredentials(new SymmetricSecurityKey(key), SecurityAlgorithms.HmacSha256Signature)
            };
            var tokenHandler = new JwtSecurityTokenHandler();
            var token        = tokenHandler.CreateToken(tokenDescriptor);

            loginResult.Token = tokenHandler.WriteToken(token);

            //await _httpContextAccessor.HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme, new ClaimsPrincipal(claimsIdentity));

            return(loginResult);
        }
Ejemplo n.º 32
0
        public async Task <IActionResult> Authunticate(UserDTO model)
        {
            IUserModel userModel = ModelManager.User;

            var config = new MapperConfiguration(cfg => cfg.CreateMap <UserDTO, IUserModel>());

            Mapper.Map <UserDTO, IUserModel>(model, userModel);

            ILoginModel loginModel = ModelManager.Login;

            loginModel.Username = userModel.Email;
            loginModel.UserId   = userModel.UserId;

            string token = string.Empty;

            if (loginModel != null)
            {
                token = JwtTokenhelper.Token(AppSettings.Secret, loginModel);
            }

            return(Ok(new { token }));
        }
Ejemplo n.º 33
0
        public void SetUp()
        {
            _recipeSizeWidth = 220;
            //Setup mocks
            _foodplanCollector = Substitute.For <IFoodplanCollector>();
            _recipeCollector   = Substitute.For <IRecipeCollector>();
            _msgService        = Substitute.For <IMessageBoxService>();
            _itemCollector     = Substitute.For <IItemCollector>();
            _userCollector     = Substitute.For <IUserCollector>();
            _shoppingListModel = Substitute.For <IShoppingListModel>();

            //Setup reals
            _loginModel      = new LoginModel(_userCollector);
            _recipeListModel = new RecipeListModel(_recipeCollector);
            _foodplanModel   = new FoodplanModel(_foodplanCollector, _shoppingListModel, _recipeListModel, _loginModel, _msgService);
            _foodplanModel.Foodplan.RecipeList = new List <Tuple <Recipe, DateTime> >();
            _sut = new RecipeListViewModel(_recipeListModel, _recipeSizeWidth, _foodplanModel, _msgService);

            //Login with Henrik
            _userCollector.DoesUserExist("", "").ReturnsForAnyArgs(true);
            _loginModel.Login("Henrik", "secret");
        }
Ejemplo n.º 34
0
        public void SetUp()
        {
            //Setup mocks
            _foodplanCollector = Substitute.For<IFoodplanCollector>();
            _recipeCollector = Substitute.For<IRecipeCollector>();
            _msgService = Substitute.For<IMessageBoxService>();
            _itemCollector = Substitute.For<IItemCollector>();
            _userCollector = Substitute.For<IUserCollector>();

            //Setup reals
            _scheduler = new TimerScheduler(2);
            _loginModel = new LoginModel(_userCollector);
            _recipeListModel = new RecipeListModel(_recipeCollector);
            _shoppingListModel = new ScheduledShoppingListModel(_itemCollector, _scheduler, _loginModel);
            _foodplanModel = new FoodplanModel (_foodplanCollector, _shoppingListModel, _recipeListModel, _loginModel, _msgService);
            _sut = new FoodplanViewModel(_foodplanModel) { Foodplan = new ObservableCollection<Recipe>() };
            _foodplanModel.Foodplan.RecipeList = new List<Tuple<Recipe, DateTime>>();

            //Login with Henrik
            _userCollector.DoesUserExist("", "").ReturnsForAnyArgs(true);
            _loginModel.Login("Henrik", "secret");
        }
Ejemplo n.º 35
0
 public LoginController()
 {
     loginModel = new LoginModel();
 }
 public LoginController()
 {
     _context = new LoginModel();
 }
Ejemplo n.º 37
0
 public void SetUp()
 {
     _collector = Substitute.For <IUserCollector>();
     _uut       = new LoginModel(_collector);
 }
Ejemplo n.º 38
0
 public void InitializeLogin(ILoginModel hostform)
 {
     this._host = hostform;
 }
Ejemplo n.º 39
0
 public void setup()
 {
     sut = new LoginModel();
 }
Ejemplo n.º 40
0
 public void Constructor_CollectorNull_ThrowsNewArgumentNullException()
 {
     Assert.Throws <ArgumentNullException>(() => _uut = new LoginModel(null));
 }
Ejemplo n.º 41
0
 private void OnAuthenticated(ILoginModel loginModel)
 {
     Token = loginModel == null ? null: loginModel.Token;
 }
 public void Constructor_CollectorNull_ThrowsNewArgumentNullException()
 {
     Assert.Throws<ArgumentNullException>(() => _uut = new LoginModel(null));
 }
Ejemplo n.º 43
0
 public LoginOperation(ILoginModel i_AuthModel)
 {
     r_AuthModel     = i_AuthModel;
     ChainedRollback = false;
 }
Ejemplo n.º 44
0
 public LoginViewModel(ILoginModel i_Model, IExrinContainer i_ExrinContainer) :
     base(i_ExrinContainer, new LoginVisualState(i_Model))
 {
     r_Model = i_Model;
 }
Ejemplo n.º 45
0
 public LoginPresenter(ILoginView loginView, ILoginModel loginModel)
 {
     _loginView = loginView;
     _loginModel = loginModel;
 }
        public ActionResult Login(ILoginModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (Membership.ValidateUser(model.UserName, model.Password))
                {
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return Redirect(returnUrl);
                    }
                    else
                    {
                        return RedirectToAction("Index", "Home");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return View(model);
        }
 public void SetUp()
 {
     _collector = Substitute.For<IUserCollector>();
     _uut = new LoginModel(_collector);
 }