public async Task <IActionResult> LoginUser(LoginViewModel loginUser)
        {
            if (!ModelState.IsValid)
            {
                foreach (var err in ModelState.Values.SelectMany(c => c.Errors))
                {
                    ViewData["signinError"] = err.ErrorMessage;
                }
                return(View("Signin"));
            }
            var user = await _userService.GetByLogin(loginUser.Login);

            if (user == null)
            {
                ViewData["signinError"] = "You didn't sign up";
                return(View("Signin"));
            }
            if (user.Password != loginUser.Password)
            {
                ViewData["signinError"] = "Wrong password";
                return(View("Signin"));
            }

            if (loginUser.RememberUser)
            {
                await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,
                                              AuthentificationService.CreatePrincipal(user));
            }
            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> CreateStudent([FromBody] StudentRegisterDTO newStudent)
        {
            newStudent.Password = AuthentificationService.EncryptPassword(newStudent.Password);
            string base64Image = newStudent.Student.ProfilePicturePath;

            if (!string.IsNullOrEmpty(base64Image))
            {
                string imageFileId = await _sharedRepository.GetNextImageId();

                newStudent.Student.ProfilePicturePath = FileManagerService.SaveImageToFile(base64Image, imageFileId);
            }

            if (await _repository.CreateNonExistingStudent(newStudent))
            {
                StudentDTO student = await _repository.StudentExists(newStudent.Student.Email);

                student.Student.ProfilePicturePath = base64Image;
                string token = JwtManager.GenerateJWToken(student.Student, student.Id.ToString());
                return(Ok(new JsonResult(token)));
            }
            else
            {
                return(Ok(new JsonResult("Email taken")));
            }
        }
Ejemplo n.º 3
0
        public void Configuration(IAppBuilder app)
        {
            ConfigureAuth(app);
            GlobalConfiguration.Configure(WebApiConfig.Register);

            // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=316888
            // app.MapSignalR("/signalr", new HubConfiguration());

            app.MapSignalR();

            app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);

            var myProvider = new AuthentificationService();
            OAuthAuthorizationServerOptions options = new OAuthAuthorizationServerOptions
            {
                AllowInsecureHttp         = true,
                TokenEndpointPath         = new PathString("/token"),
                AccessTokenExpireTimeSpan = TimeSpan.FromDays(1),
                Provider = myProvider
            };

            app.UseOAuthAuthorizationServer(options);
            app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());


            HttpConfiguration config = new HttpConfiguration();

            WebApiConfig.Register(config);
        }
Ejemplo n.º 4
0
 public LoginPageViewModel(GameService gameService, AuthentificationService authentificationService, INavigationService navigationService)
 {
     NavigationService        = navigationService;
     _gameService             = gameService;
     _authentificationService = authentificationService;
     Login = new Login();
 }
        public async Task <IActionResult> RegisterUser(RegistrationViewModel registrationUser)
        {
            if (!ModelState.IsValid)
            {
                foreach (var err in ModelState.Values.SelectMany(c => c.Errors))
                {
                    ViewData["signupError"] = err.ErrorMessage;
                }
                return(View("Signup"));
            }
            var user = _mapper.Map <HousingUser>(registrationUser);

            if (await _userService.HasEntity(user))
            {
                ViewData["signupError"] = "User with such login already exists";
                return(View("Signup"));
            }
            user = await _userService.Create(user);

            if (user != null)
            {
                await HttpContext.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme,
                                              AuthentificationService.CreatePrincipal(user));
            }
            return(RedirectToAction("Index", "Home"));
        }
Ejemplo n.º 6
0
        public void SetupAuthTest()
        {
            //2401b58e19ceab051ae3d9c1fda093f2
            AuthentificationService a = new AuthentificationService();

            a.SetupAuth();
            Assert.AreEqual("2401b58e19ceab051ae3d9c1fda093f2", Function.GetMD5(@"users.xml"));
            File.Delete(@"users.xml");
        }
Ejemplo n.º 7
0
        public void UserIDExistTest()
        {
            AuthentificationService a = new AuthentificationService();

            a.SetupAuth();
            a.SignupUser(new Utility.Network.Users.CryptedCredentials("User1", "abc"));
            Assert.AreEqual(true, a.UserIDExist("abc"));
            Assert.AreEqual(false, a.UserIDExist("abC"));
            File.Delete(@"users.xml");
        }
Ejemplo n.º 8
0
        public void EditUserTest()
        {
            //06a0f0fcffbf4f74aac1dc5b22afb9b7
            AuthentificationService a = new AuthentificationService();

            a.SetupAuth();
            a.SignupUser(new Utility.Network.Users.CryptedCredentials("User1", "abc"));
            a.EditUser("abc", new Utility.Network.Users.User(new Utility.Network.Users.CryptedCredentials("User2", "abd")));
            Assert.AreEqual("06a0f0fcffbf4f74aac1dc5b22afb9b7", Function.GetMD5(@"users.xml"));
            File.Delete(@"users.xml");
        }
Ejemplo n.º 9
0
        public void SignupUserTest()
        {
            //e0c5d6856147fbaf2888fc1720e9f7c8
            AuthentificationService a = new AuthentificationService();

            a.SetupAuth();
            a.SignupUser(new Utility.Network.Users.CryptedCredentials("User1", "abc"));

            Assert.AreEqual("e0c5d6856147fbaf2888fc1720e9f7c8", Function.GetMD5(@"users.xml"));
            File.Delete(@"users.xml");
        }
Ejemplo n.º 10
0
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            AuthentificationService authentificationService = new AuthentificationService(actionContext);

            if (!authentificationService.IsAuthorized())
            {
                base.OnAuthorization(actionContext);
            }
            else
            {
                return;
            }
        }
        private IEnumerable <Claim> LoadRoles(string login, string password)
        {
            IAuthentificationService ause = new AuthentificationService();

            yield return(new Claim(ClaimTypes.Role, ause.getRoleFromLoginetPassword(login, password)));

            yield return(new Claim(ClaimTypes.Name, ause.getNameFromLoginAndPasswod(login, password)));

            yield return(new Claim(ClaimTypes.Email, ause.Authentification(login, password).e_mail));

            yield return(new Claim(ClaimTypes.PrimarySid, ause.Authentification(login, password).id.ToString()));

            // yield return new Claim(ClaimTypes.Name, ause.Authentification(login, password).name);
        }
Ejemplo n.º 12
0
        public void OnAuthorization(AuthorizationContext filterContext)
        {
            AuthentificationService authentificationService = new AuthentificationService(filterContext);

            if (!authentificationService.IsAuthorized())
            {
                var urlHelper = new UrlHelper(filterContext.RequestContext);
                filterContext.Result = new RedirectResult(urlHelper.Action("Logon", "Home"));
            }
            else
            {
                return;
            }
        }
Ejemplo n.º 13
0
 public AuthentificationServiceTests()
 {
     _userList = new List <User>();
     _userTest = new User()
     {
         Login          = "******",
         HashedPassword = "******",
         PasswordSalt   = "salt"
     };
     _userList.Add(_userTest);
     _userRepository = new Mock <IRepository <User> >();
     _cryptoService  = new Mock <ICryptoService>();
     _userRepository.Setup(user => user.GetAll()).Returns(_userList);
     _authentificationService = new AuthentificationService(_userRepository.Object, _cryptoService.Object);
 }
Ejemplo n.º 14
0
        public User Display()
        {
            bool loginSucceeded = false;

            User user;

            do
            {
                Console.Clear();
                Console.WriteLine("Please login.\n\n");

                Console.Write("Username: "******"Password: "******"\nIs this correct? [Y]es [N]o");

                var keyInfo = Console.ReadKey(true);

                if (keyInfo.Key == ConsoleKey.Y)
                {
                    if (user == null)
                    {
                        Console.WriteLine("Wrong! Try again.");
                        Thread.Sleep(2000);
                    }
                    else
                    {
                        loginSucceeded = true;
                    }
                }
            } while (!loginSucceeded);

            return(user);
        }
Ejemplo n.º 15
0
        static void Main(string[] args)
        {
            var receptionistView = new ReceptionistMainView();
            var adminView        = new AdminMainView();

            Console.Write("Username: "******"Password: "******"Succesfully logged in");

                Console.WriteLine($"Role {user.Role}");
                if (user.Role == "Receptionist")
                {
                    receptionistView.Display();
                }
                if (user.Role == "Admin")
                {
                    adminView.Display();
                }
                if (user.Role == "Vetrinarian")
                {
                }
            }
            else
            {
                Console.WriteLine("Access denied!");
            }
        }
Ejemplo n.º 16
0
        public IService Create(ServiceName serviceName)
        {
            IService service = null;

            switch (serviceName)
            {
            case ServiceName.REGIST:
                service = new RegistrationService(dbAccessor, lineMessenger);
                break;

            case ServiceName.AUTH:
                service = new AuthentificationService(dbAccessor);
                break;

            case ServiceName.UNREGIST:
                service = new UnregistrationService(dbAccessor);
                break;

            case ServiceName.NOTIFY:
                service = new NotificationService(dbAccessor, eventInfoConverter, lineMessenger);
                break;
            }
            return(service);
        }
Ejemplo n.º 17
0
        public async Task <ActionResult> LogUserIn([FromBody] AccountLogInDTO userCredentials)
        {
            string savedPwd = await _repository.GetPassword(userCredentials.Email);

            if (savedPwd != null)
            {
                if (AuthentificationService.IsPasswordCorrect(savedPwd, userCredentials.Password))
                {
                    StudentDTO student = await _repository.StudentExists(userCredentials.Email);

                    student.Student.ProfilePicturePath = FileManagerService.LoadImageFromFile(student.Student.ProfilePicturePath);
                    string token = JwtManager.GenerateJWToken(student.Student, student.Id.ToString());
                    return(Ok(new JsonResult(token)));
                }
                else
                {
                    return(Ok(new JsonResult("Wrong password")));
                }
            }
            else
            {
                return(Ok(new JsonResult("Non-existent email")));
            }
        }
        public ActionResult Login(staff model, string returnUrl)
        {
            IAuthentificationService ause = new AuthentificationService();

            staff em = new staff();

            model             = ause.Authentification(model.login, model.mdp);
            ViewBag.ReturnUrl = returnUrl;

            if (!ModelState.IsValid)
            {
                return(View(model));
            }


            if (model != null)
            {
                //  if ((model.Username == "ramzi") && (model.Password) == "ramzi") {
                // L'authentification est réussie,
                // injecter l'identifiant utilisateur dans le cookie d'authentification :
                var userClaims = new List <Claim>();
                // Identifiant utilisateur :
                userClaims.Add(new Claim(ClaimTypes.NameIdentifier, model.login));
                // Rôles utilisateur :
                userClaims.AddRange(LoadRoles((model.login), (model.mdp)));
                var claimsIdentity        = new ClaimsIdentity(userClaims, DefaultAuthenticationTypes.ApplicationCookie);
                var ctx                   = Request.GetOwinContext();
                var authenticationManager = ctx.Authentication;
                authenticationManager.SignIn(claimsIdentity);
                // Rediriger vers l'URL d'origine :
                if (Url.IsLocalUrl(ViewBag.ReturnUrl))
                {
                    return(Redirect(ViewBag.ReturnUrl));
                }
                // Par défaut, rediriger vers la page d'accueil :
                em = model;


                if (model.function == "user")
                {
                    return(RedirectToAction("Index", "Home"));
                }

                if (model.function == "staff")
                {
                    return(RedirectToAction("IndexBack", "Home"));
                }

                if (model.function == "doctor")
                {
                    return(RedirectToAction("Patientrequest", "Consultation"));
                }

                else
                {
                    return(null);
                }
            }
            else
            {
                ModelState.AddModelError(string.Empty, "Le nom d'utilisateur ou le mot de passe est incorrect.");
                return(View(model));
            }
        }
Ejemplo n.º 19
0
        public void LoginUser(string username, string password)
        {
            User user = userRep.GetUser(username, password);

            AuthentificationService.AuthUser(user.Id);
        }