public async Task <IActionResult> Login(LogInVM viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            // Check if credentials is valid (and set auth cookie)
            if (!await accountrepository.TryLoginAsync(viewModel))
            {
                // Show login error
                ModelState.AddModelError(nameof(LogInVM.Name), "Felaktigt användarnamn eller lösenord");
                return(View(viewModel));
            }


            // Redirect user
            if (string.IsNullOrWhiteSpace(viewModel.ReturnUrl))
            {
                return(RedirectToAction(nameof(AssignmentsController.CourseFrontPage), "Assignments"));
            }

            else
            {
                return(Redirect(viewModel.ReturnUrl));
            }
        }
        public ActionResult LogIn(LogInVM model)
        {
            if (ModelState.IsValid)
            {
                UserVM user = _userService.GetUserByEmail(model.Email);

                if (user == null || user.Password != model.Password)
                {
                    ModelState.AddModelError("", "Неверный логин или пароль.");
                    return(View("LogIn", model));
                }
                else
                {
                    ClaimsIdentity claim = new ClaimsIdentity("ApplicationCookie", ClaimsIdentity.DefaultNameClaimType, ClaimsIdentity.DefaultRoleClaimType);
                    claim.AddClaim(new Claim(ClaimTypes.NameIdentifier, user.Id.ToString(), ClaimValueTypes.String));
                    claim.AddClaim(new Claim(ClaimsIdentity.DefaultNameClaimType, user.Name, ClaimValueTypes.String));
                    claim.AddClaim(new Claim(ClaimsIdentity.DefaultIssuer, user.Id.ToString(), ClaimValueTypes.String));
                    claim.AddClaim(new Claim("http://schemas.microsoft.com/accesscontrolservice/2010/07/claims/identityprovider",
                                             "OWIN Provider", ClaimValueTypes.String));
                    AuthenticationManager.SignOut();
                    AuthenticationManager.SignIn(new AuthenticationProperties
                    {
                        IsPersistent = true
                    }, claim);
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View("LogIn", model));
        }
Exemplo n.º 3
0
        public async Task <ActionResult> Login(LogInVM user)
        {
            if (ModelState.IsValid)
            {
                var status = await SignIn.PasswordSignInAsync(user.UserName, user.Password,
                                                              isPersistent : false, shouldLockout : true);



                switch (status)
                {
                case SignInStatus.Success:
                    return(RedirectToAction("Index", "Home"));

                case SignInStatus.Failure:
                    ViewBag.Message = "Wrong username or password";
                    break;

                default:
                    break;
                }
            }
            // Not OK
            return(View(user));
        }
        public ActionResult LogIn(LogInVM login)
        {
            if (ModelState.IsValid)
            {
                // This doesn't count login failures towards account lockout
                // To enable password failures to trigger account lockout, set lockoutOnFailure: true
                var result = _signInManager.PasswordSignInAsync(login.Email, login.Password, login.RememberMe, lockoutOnFailure: false).Result;
                if (result.Succeeded)
                {
                    if (Helpers.Helpers.IsUserActive(login.Email, _employeeLogic))
                    {
                        ModelState.AddModelError(string.Empty, "Usuario desactivado.");
                        return(View());
                    }

                    _logger.LogInformation("User logged in.");
                    return(RedirectToAction("Index", "Home"));
                }
                if (result.IsLockedOut)
                {
                    _logger.LogWarning("User account locked out.");
                    return(RedirectToPage("./Lockout"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Correo o contraseña incorrecto.");
                    return(View());
                }
            }
            return(View());
        }
Exemplo n.º 5
0
        public async Task <bool> SignInUser(LogInVM vM)
        {
            var result = await signInManager.PasswordSignInAsync(
                vM.UserName, vM.Password, false, false);

            return(result.Succeeded);
        }
Exemplo n.º 6
0
        public async Task <IActionResult> LogIn(LogInVM model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var identity = new ClaimsIdentity(CookieAuthenticationDefaults.AuthenticationScheme);
                identity.AddClaim(new Claim(ClaimTypes.NameIdentifier, "Id"));
                identity.AddClaim(new Claim(ClaimTypes.Name, "UserName"));

                var principal = new ClaimsPrincipal(identity);

                await HttpContext.SignInAsync(principal);

                var result = await _signInManager.PasswordSignInAsync(model.username, model.password, model.remember_me, false);

                if (result.Succeeded)
                {
                    if (!string.IsNullOrEmpty(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("index", "home"));
                    }
                }
                ModelState.AddModelError(string.Empty, "Invalid log in attempt.");
            }
            return(View(model));
        }
        public ActionResult LogOnModal(LogInVM userLogin)
        {
            if (ModelState.IsValid)
            {
                UserVM user = _userBLL.UserLogIn(userLogin);

                if (user != null)
                {
                    Session["Kunde"] = user;

                    if (user.Admin)
                    {
                        return(Json(JsonConvert.SerializeObject("admin")));
                    }
                    return(Redirect(Request.UrlReferrer.PathAndQuery));
                }
            }
            string result = userLogin.FindEmptyFields(userLogin);

            if (result != null)
            {
                return(Json(JsonConvert.SerializeObject(result)));
            }
            return(Json(JsonConvert.SerializeObject("Feil brukernavn eller passord! Brukeren kan også være inaktiv.")));
        }
Exemplo n.º 8
0
        public async Task <IActionResult> LogIn(LogInVM model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                var result = await _accountService.LogInAsync(model);

                if (result.Succeeded)
                {
                    _loger.LogInformation(string.Format("The user: {0} logs in.", model.Email));
                    if (!string.IsNullOrEmpty(returnUrl))
                    {
                        return(LocalRedirect(returnUrl));
                    }
                    return(RedirectToAction("Index", "Home"));
                }
                if (result.IsLockedOut)
                {
                    return(RedirectToAction("Index", "Message", new { Message = IdMessage.AccountLock }));
                }
                if (result.IsNotAllowed)
                {
                    ModelState.AddModelError("", "Adres Email nie został potwierdzony.");
                }
                else
                {
                    ModelState.AddModelError("", "Niepoprawny login lub hasło");
                }
            }
            return(View(model));
        }
Exemplo n.º 9
0
        public static bool log_in(LogInVM logInModel)
        {
            DataContext db = new DataContext();

            byte[] passwordbyte = System.Text.Encoding.ASCII.GetBytes(logInModel.Password);
            System.Security.Cryptography.MD5 md5 = System.Security.Cryptography.MD5.Create();
            byte[] passhash  = md5.ComputeHash(passwordbyte);
            string finalPass = "";

            for (int i = 0; i < passhash.Length; i++)
            {
                finalPass += passhash[i];
            }
            User login = db.Users.Where(x => x.EMail == logInModel.EMail && x.Password == logInModel.Password).FirstOrDefault();

            if (login != null)
            {
                //save imformation on session
                AdminVM adminmodel = new AdminVM();
                adminmodel.ID      = login.ID;
                adminmodel.EMail   = login.EMail;
                adminmodel.Name    = login.Name;
                adminmodel.SurName = login.SurName;

                Tools.SetCookies(adminmodel);
                Tools.SaveAdminInSession(adminmodel);


                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 10
0
        public ActionResult LogIn(LogInVM user, string ReturnUrl)
        {
            DAL_Library dal_Library = new DAL_Library();
            var         thisUser    = dal_Library.GetUserList().Where(u => u.username == user.username && u.password == user.password).FirstOrDefault();

            if (thisUser == null)
            {
                ViewBag.Login = "******";
                return(View("LogIn", user));
            }
            else
            {
                Session["userId"]   = thisUser.userId;
                Session["username"] = thisUser.username;

                if (Url.IsLocalUrl(ReturnUrl))
                {
                    return(Redirect(ReturnUrl));
                }
                else
                {
                    return(RedirectToAction("Index", "Home"));
                }
            }
        }
Exemplo n.º 11
0
        public JsonResult LogIn(LogInVM vm)
        {
            try
            {
                if (SessionManager.SecurityCode != vm.SecurityCode)
                {
                    return(Json(new { Result = false, Message = "Güvenlik Kodu Doğrulanamadı!" }));
                }

                User user =
                    _us.Get(x => x.UserName == vm.UserName && x.Password == vm.Password);

                if (user != null)
                {
                    SessionManager.ActiveUser = user;

                    return(Json(new { Result = true }));
                }

                return(Json(new { Result = false, Message = "Kullanıcı Adı yada Şifre Hatalı!" }));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = false, ex.Message }));
            }
        }
Exemplo n.º 12
0
        public async Task <ActionResult> LogIN(LogInVM _User)
        {
            if (ModelState.IsValid == true)
            {
                ApplicationUserManager manager = new ApplicationUserManager(
                    new ApplicationUserStore(new ApplicationDbContext())
                    );
                ApplicationUser AppUser = await manager.FindByNameAsync(_User.UserName);

                if (AppUser != null)
                {
                    if (await manager.CheckPasswordAsync(AppUser, _User.Password))
                    {
                        IAuthenticationManager   Authentication = HttpContext.GetOwinContext().Authentication;
                        ApplicationSignInManager signInManager  = new ApplicationSignInManager(manager, Authentication);
                        await signInManager.SignInAsync(AppUser, false, false);

                        if (User.IsInRole("Admin"))
                        {
                            return(RedirectToAction("Edit", "Admins", new { id = AppUser.Id }));
                        }
                        else
                        {
                            return(RedirectToAction("MYPage", "Voters", new { id = AppUser.Id }));
                        }
                    }
                    return(View(_User));
                }
                return(View(_User));
            }
            return(View(_User));
        }
Exemplo n.º 13
0
        public IActionResult LogIn(string returnURL = "")
        {
            var model = new LogInVM
            {
                ReturnUrl = returnURL
            };

            return(View(model));
        }
Exemplo n.º 14
0
        public ActionResult UserLogin(LogInVM entity)
        {
            string OldHASHValue = string.Empty;

            byte[] SALT = new byte[GenerateSaltKey._SaltLengthLimit];

            try
            {
                using (db = new CodeliteEntities1())
                {
                    // Ensure we have a valid viewModel to work with
                    if (!ModelState.IsValid)
                    {
                        return(View(entity));
                    }

                    //Retrive Stored HASH Value From Database According To Username (one unique field)
                    var userInfo = db.user_Credential.Where(s => s.user_Name == entity.UserName.Trim()).FirstOrDefault();

                    //Assign HASH Value
                    if (userInfo != null)
                    {
                        OldHASHValue = userInfo.HASH;
                        SALT         = userInfo.SALT;
                    }

                    bool isLogin = LogInVM.CompareHashValue(entity.Password, entity.UserName, OldHASHValue, SALT);

                    if (isLogin)
                    {
                        //Login Success
                        //For Set Authentication in Cookie (Remeber ME Option)
                        SignInRemember(entity.UserName, entity.IsRememberMe);

                        //Set A Unique ID in session
                        Session["UserID"] = userInfo.user_Name;

                        // If we got this far, something failed, redisplay form
                        // return RedirectToAction("Index", "Dashboard");
                        return(RedirectToLocal(entity.ReturnURL));
                    }
                    else
                    {
                        //Login Fail
                        ModelState.AddModelError("", "Access Denied! Wrong Credential");
                        return(View(entity));
                    }
                }
            }
            catch
            {
                throw;
            }
        }
Exemplo n.º 15
0
        public async Task <bool> TryLoginAsync(LogInVM viewModel)
        {
            // Create DB schema (first time)
            //var createSchemaResult = await identityContext.Database.EnsureCreatedAsync();

            // Create a hard coded user (first time)
            //var createResult = await userManager.CreateAsync(new IdentityUser("user"), "Password_123");

            var loginResult = await signInManager.PasswordSignInAsync(viewModel.Name, viewModel.Password, false, false);

            return(loginResult.Succeeded);
        }
Exemplo n.º 16
0
        public ActionResult LogIn(LogInVM login)
        {
            AuthenticationManager.Authenticate(login.Username, login.Password);

            if (AuthenticationManager.LoggedUser == null)
            {
                return(RedirectToAction("LogIn", "Home"));
            }
            else
            {
                return(RedirectToAction("index", "TaskManagement"));
            }
        }
Exemplo n.º 17
0
        public ActionResult LogIn(LogInVM login)
        {
            AuthenticationManager.Authenticate(login.Email, login.Password);

            if (AuthenticationManager.LoggedUser == null)
            {
                return(RedirectToAction("LogIn", "Home"));
            }
            else
            {
                return(RedirectToAction("Index", "Appointment"));
            }
        }
        public IActionResult AuthProces(string username, string pass)
        {
            LogInVM log = db.Korisnici_OrganizacionaJedinica.Include(a => a.korisnici).Include(a => a.organizacionaJedinica).Include(a => a.organizacionaJedinica.organizacija).Where(a => a.korisnici.Korisnicko_Ime == username && a.korisnici.Lozinka == pass).Include(a => a.korisnici.uloge).Select(x => new LogInVM
            {
                organisation   = x.organizacionaJedinica.organizacija.Naziv,
                organisationId = x.organizacionaJedinica.organizacija.Organizacija_ID,
                orgJed         = x.organizacionaJedinica.Naziv,
                orgJedId       = x.organizacionaJedinica.OrganizacionaJedinica_ID,
                password       = x.korisnici.Lozinka,
                role           = x.korisnici.uloge.Naziv,
                roleId         = x.korisnici.uloge.Uloge_ID,
                user           = x.korisnici.Ime.ToString() + " " + x.korisnici.Prezime.ToString(),
                userId         = x.korisnici.Korisnici_ID,
                username       = x.korisnici.Korisnicko_Ime
            }).FirstOrDefault();

            if (log == null)
            {
                string msg = "Niste unijeli ispravne podatke";
                TempData["poruka"] = msg;
            }
            else
            {
                HttpContext.Session.SetString("organisation", log.organisation);
                HttpContext.Session.SetInt32("organisation ID", log.organisationId.Value);
                HttpContext.Session.SetString("orgJed", log.orgJed);
                HttpContext.Session.SetInt32("orgJed ID", log.orgJedId.Value);
                HttpContext.Session.SetString("role", log.role);
                HttpContext.Session.SetInt32("role ID", log.roleId.Value);
                HttpContext.Session.SetString("user", log.user);
                HttpContext.Session.SetInt32("user ID", log.userId.Value);
                HttpContext.Session.SetString("username", log.username);

                switch (log.role)
                {
                case "SuperAdmin": return(Redirect("/SuperAdmin/SuperAdmin/Index"));      /*break;*/

                case "Admin-Org": return(Redirect("/AdminOrg/AdminOrg/Index"));           /*break;*/

                case "User": return(Redirect("/User/User/Index"));                        /*break;*/

                case "User-Report": return(Redirect("/UserReport/UserReport/Index"));     /*break;*/

                case "Admin-Org-Jed": return(Redirect("/AdminOrgJed/AdminOrgJed/Index")); /*break;*/
                }
            }

            return(Redirect("/Auth/index"));
        }
Exemplo n.º 19
0
        public async Task <ActionResult> AddUser(AppUserVM model)
        {
            if (ModelState.IsValid)
            {
                var user = new AppUser
                {
                    FirstName   = model.FirstName,
                    LastName    = model.LastName,
                    UserName    = model.UserName,
                    Email       = model.Email,
                    PhoneNumber = model.PhoneNumber,
                    Address     = model.Address,
                    PostalCode  = model.PostalCode,
                };

                var res = await UserManager.CreateAsync(user, model.Password);

                if (res.Succeeded)
                {
                    var regUser = await UserManager.FindByNameAsync(model.UserName);


                    //    if (model.Admin == true)
                    //        await UserManager.AddToRoleAsync(regUser.Id, "Admin");
                    //    else
                    //        await UserManager.AddToRoleAsync(regUser.Id, "User");

                    await UserManager.AddToRoleAsync(regUser.Id, "User");



                    LogInVM vmod = new LogInVM();


                    vmod.UserName = model.UserName;
                    vmod.Password = model.Password;
                    await Login(vmod);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    return(View("RegUser", model));
                }
            }
            // Not OK
            return(View("RegUser", model));
        }
        public ActionResult LogIn(LogInVM logInModel)
        {
            try
            {
                bool s = DBService.log_in(logInModel);

                if (s)
                {
                    return(Redirect("~/WebArea/Admin/Index"));
                }

                return(View());
            }
            catch
            {
                return(View());
            }
        }
Exemplo n.º 21
0
        public ActionResult UserLogin(string returnURL)
        {
            var userinfo = new LogInVM();

            try
            {
                // We do not want to use any existing identity information
                EnsureLoggedOut();

                // Store the originating URL so we can attach it to a form field
                userinfo.ReturnURL = returnURL;
                return(View(userinfo));
            }
            catch
            {
                throw;
            }
        }
Exemplo n.º 22
0
        public async Task <IActionResult> Login(LogInVM loginUser)
        {
            if (ModelState.IsValid)
            {
                Microsoft.AspNetCore.Identity.SignInResult result = await _signInManager.PasswordSignInAsync(loginUser.UserName, loginUser.Password, false, false);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Index", "Home"));
                }

                if (result.IsLockedOut)
                {
                    ModelState.AddModelError("Lock-out", "Too many login attempts");
                }
            }
            return(View(loginUser));
        }
Exemplo n.º 23
0
        public async Task <IActionResult> Login(LogInVM vM, string returnUrl = null)
        {
            returnUrl = returnUrl ?? Url.Content("~");
            if (ModelState.IsValid)
            {
                var result = await signInManager.PasswordSignInAsync(vM.UserName, vM.Password, false, true);

                if (result.Succeeded)
                {
                    return(RedirectToAction("Home"));
                }
                else
                {
                    ModelState.AddModelError(string.Empty, "Tyvärr kunde du inte loggas in, försök igen");
                    return(RedirectToAction("Login"));
                }
            }
            return(Redirect("/"));
        }
Exemplo n.º 24
0
        public ActionResult LogIn(LogInVM vm)
        {
            var userService = ServiceFactory.getUserServices();
            var le          = new LoginEntity {
                Username = vm.Username, Password = vm.Password
            };

            try
            {
                var userId = userService.Login(le);
                var user   = userService.Get(userId);
                Session["user"] = user;
                return(RedirectToAction("Search", "Event"));
            }
            catch (Exception e)
            {
                ModelState.AddModelError("", e.Message);
                return(View(vm));
            }
        }
Exemplo n.º 25
0
        /// <summary>
        /// Authentication of user credentials on the credentials in the database.
        /// </summary>
        /// <param name="logInInfo">User credentials</param>
        /// <returns>A customer object if authentication passed, null if not.</returns>
        public UserVM UserLogIn(LogInVM logInInfo)
        {
            try
            {
                using (var db = new VideoDB())
                {
                    var email    = logInInfo.Email;
                    var password = logInInfo.PassWord;
                    var dbUser   = db.Users.FirstOrDefault(k => k.Email == logInInfo.Email);

                    if (dbUser == null || !dbUser.Active)
                    {
                        return(null);
                    }

                    if (dbUser != null && ControlPassWord(dbUser, password))
                    {
                        UserVM user = new UserVM
                        {
                            Id        = dbUser.Id,
                            FirstName = dbUser.FirstName,
                            SurName   = dbUser.SurName,
                            Address   = dbUser.Address,
                            Email     = email,
                            PhoneNr   = dbUser.PhoneNr,
                            PostalNr  = dbUser.PostalAddress.PostalCode,
                            Postal    = dbUser.PostalAddress.Postal,
                            PassWord  = null,
                            Admin     = dbUser.Admin
                        };
                        return(user);
                    }
                    return(null);
                }
            }
            catch (Exception e)
            {
                new ErrorLogRepository().CreateError("Oblig1.DAL.LogOnRepository.UserLogIn(LogINVM  logininfo)", logInInfo.ToString(), e);
                return(null);
            }
        }
Exemplo n.º 26
0
        public async Task <IActionResult> LogIn(LogInVM model)
        {
            if (ModelState.IsValid)
            {
                var result = await signInManager.PasswordSignInAsync(model.Username, model.Password, isPersistent : model.RememberMe, lockoutOnFailure : false);

                if (result.Succeeded)
                {
                    if (!string.IsNullOrEmpty(model.ReturnUrl) && Url.IsLocalUrl(model.ReturnUrl))
                    {
                        return(Redirect(model.ReturnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
            }
            ModelState.AddModelError("", "Invalid username/password.");
            return(View(model));
        }
Exemplo n.º 27
0
        public ActionResult SignUp(RegisterVM model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var userExist = _userService.EmailExist(model.Email);

            if (userExist)
            {
                ModelState.AddModelError("Email", "User with this email already exists");
                return(View(model));
            }

            _userService.CreateUser(model);
            LogInVM logIn = new LogInVM()
            {
                Email    = model.Email,
                Password = model.Password
            };

            return(RedirectToAction("AutomaticallyLogIn", logIn));
        }
Exemplo n.º 28
0
 public async Task <SignInResult> LogInAsync(LogInVM model)
 {
     return(await _signInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, true));
 }
Exemplo n.º 29
0
 public CheckLogInCommand(LogInVM currentVM)
 {
     this.CurrentVM = currentVM;
 }
Exemplo n.º 30
0
 public IHttpActionResult SaveEmployee([FromBody] LogInVM value)
 {
     return(Ok(new { data = value }));
 }