示例#1
0
 public ActionResult LogIn(UserLoginView ULV, string returnUrl)
 {
     if (ModelState.IsValid)
     {
         UserManager UM       = new UserManager();
         string      password = UM.GetUserPassword(ULV.NIK);
         if (string.IsNullOrEmpty(password))
         {
             ModelState.AddModelError("", "NIK atau password salah.");
         }
         else
         {
             if (UM.IsPasswordMatch(ULV.NIK, ULV.Password)) // memanggil fungsi cek password hashed Bcrypt
             {
                 FormsAuthentication.SetAuthCookie(ULV.NIK, false);
                 return(RedirectToAction("Index", "Home"));
             }
             else
             {
                 ModelState.AddModelError("", "Password yang dimasukkan salah.");
             }
         }
     }
     // If we got this far, something failed, redisplay form
     return(View(ULV));
 }
        public ActionResult Login(UserLoginView model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                UserManager userManager = new UserManager();
                string      password    = userManager.GetUserPassword(model.LoginName);

                if (string.IsNullOrEmpty(password))
                {
                    ModelState.AddModelError("", "The user login or password provided is incorrect.");
                }
                else
                {
                    if (model.Password.Equals(password))
                    {
                        FormsAuthentication.SetAuthCookie(model.LoginName, false);
                        return(RedirectToAction("Index", "Home"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "The password provided is incorrect.");
                    }
                }
            }
            return(View(model));
        }
示例#3
0
        public ActionResult LogIn(UserLoginView ULV, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                UserManager UM       = new UserManager();
                string      password = UM.GetUserPassword(ULV.LoginName);

                if (string.IsNullOrEmpty(password))
                {
                    ModelState.AddModelError("", "The user login or password provided is incorrect.");
                }
                else
                {
                    if (ULV.Password.Equals(password))
                    {
                        FormsAuthentication.SetAuthCookie(ULV.LoginName, false);
                        return(RedirectToAction("Welcome", "Home"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "The password provided is incorrect.");
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(ULV));
        }
        public IActionResult Token([FromBody] UserLoginView model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Could not create token"));
            }

            var dbUser = _userService.Login(model);

            if (!dbUser)
            {
                return(Unauthorized(new Exception("Λάθος username ή password")));
            }

            var claims = new List <Claim>();

            claims.Add(new Claim("username", "Administrator"));
            claims.Add(new Claim("role", "admin"));

            var key   = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Jwt:Key"]));
            var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);

            var token = new JwtSecurityToken(_config["Jwt:Issuer"],
                                             _config["Jwt:Issuer"],
                                             claims,
                                             expires: DateTime.UtcNow.AddHours(24),
                                             signingCredentials: creds);

            return(Ok(new { token = new JwtSecurityTokenHandler().WriteToken(token) }));
        }
示例#5
0
        public async Task <ActionResult> Login(UserLoginView userLogin)
        {
            var command = new UserLoginCommand(userLogin.Email, userLogin.Password);
            var result  = await _mediator.SendCommand <UserLoginCommand, UserLoginResponse>(command).ConfigureAwait(false);

            return(CustomResponse <UserLoginResponse>(result));
        }
        public ActionResult LogIn(UserLoginView ULV, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                UserManager UM   = new UserManager();
                var         user = UM.GetUserFromDatabase(ULV.LoginName);

                string password = UM.GetUserPassword(ULV.LoginName);

                if (string.IsNullOrEmpty(password))
                {
                    ModelState.AddModelError("", "The user login or password provided is incorrect.");
                }
                else
                {
                    if (ULV.Password.Equals(password))
                    {
                        FormsAuthentication.SetAuthCookie(ULV.LoginName, false);

                        return(RedirectToAction("Index", "Home", new { Id = user.SYSUserID }));
                    }
                    else
                    {
                        ModelState.AddModelError("", "The password provided is incorrect.");
                    }
                }
            }
            return(View(ULV));
        }
示例#7
0
        public async Task <IActionResult> Token([FromBody] UserLoginView model)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest("Could not create token"));
            }

            var dbUser = await _userService.Login(model);

            if (dbUser == null)
            {
                return(Unauthorized(new Exception("Λάθος username ή password")));
            }

            var claims = new List <Claim>();

            claims.Add(new Claim("username", dbUser.Username));
            claims.Add(new Claim("email", dbUser.Email));
            claims.Add(new Claim("title", dbUser.Title));
            claims.Add(new Claim("userid", dbUser.Id));
            claims.Add(new Claim("role", dbUser.Role.ToString()));
            claims.Add(new Claim("sites", string.Join(';', dbUser.Sites)));

            var key   = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(_config["Jwt:Key"]));
            var creds = new SigningCredentials(key, SecurityAlgorithms.HmacSha256);

            var token = new JwtSecurityToken(_config["Jwt:Issuer"],
                                             _config["Jwt:Issuer"],
                                             claims,
                                             expires: DateTime.UtcNow.AddHours(8),
                                             signingCredentials: creds);

            return(Ok(new { token = new JwtSecurityTokenHandler().WriteToken(token) }));
        }
示例#8
0
        public ActionResult LogIn(UserLoginView ulv, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                UserManager um       = new UserManager();
                string      password = um.GetUserPassword(ulv.LoginName);

                if (string.IsNullOrEmpty(password))
                {
                    ModelState.AddModelError("", "The User Login or Password Provided is Incorrect");
                }
                else
                {
                    if (ulv.Password.Equals(password))
                    {
                        FormsAuthentication.SetAuthCookie(ulv.LoginName, false);
                        return(RedirectToAction("Welcome", "Home"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "The Password Provided is Incorrect");
                    }
                }
            }
            return(View(ulv));
        }
示例#9
0
 public ActionResult Login([Bind(Include = "Username, Password")] UserLoginView userLoginView)
 {
     if (ModelState.IsValid)
     {
         var usr = db.Users.Where(u => u.UserName == userLoginView.UserName).FirstOrDefault();
         if (usr != null)
         {
             if (usr.Password == userLoginView.Password)
             {
                 var session = new UserSession()
                 {
                     UserID   = usr.UserID,
                     UserName = usr.UserName,
                 };
                 this.Session["ValidateSession"] = session;
                 return(RedirectToAction("LoggedIn"));
             }
             else
             {
                 ViewBag.InvalidPassword = true;
                 userLoginView.Password  = null;
                 return(View("Login"));
             }
         }
         return(RedirectToAction("Login"));
     }
     return(View(userLoginView));
 }
        public ActionResult Login(UserLoginView loginView)
        {
            if (ModelState.IsValid)
            {
                User userFound = DB.Users.Where(u => u.UserName == loginView.UserName).FirstOrDefault();
                if (userFound == null)
                {
                    ModelState.AddModelError("UserName", "This username does not exist");
                    return View();
                }
                else
                {
                    if (userFound.Password != loginView.Password)
                    {
                        ModelState.AddModelError("password", "Wrong password");
                        return View();
                    }
                }
                OnlineUsers.AddSessionUser(userFound);
            }
            else
                return View();

            return RedirectToAction("Index", "Home");
        }
示例#11
0
        public IHttpResponse Login(UserLoginView view)
        {
            if (!this.userService.Validate(view))
            {
                return(BadRequestErrorWithView("Invalid username or password!"));
            }

            var user = this.userService.GetUser(view.Username);

            var mvcUser = new MvcUserInfo
            {
                Username = user.Username,
                Role     = user.Role.ToString(),
                Info     = user.Email
            };
            var cookieContent = this.UserCookieService.GetUserCookie(mvcUser);

            var cookie = new HttpCookie(".auth-cakes", cookieContent, 7)
            {
                HttpOnly = true
            };

            this.Response.Cookies.Add(cookie);

            return(this.Redirect("/"));
        }
示例#12
0
        public async Task <UserProfile> LoginUser(UserLoginView loginParam)
        {
            UserProfile userProfile = new UserProfile();
            var         uriPost     = new Uri(hostUrl + "api/login");

            try
            {
                var jsonData = JsonConvert.SerializeObject(loginParam);
                var content  = new StringContent(jsonData, Encoding.UTF8, "application/json");
                HttpResponseMessage response = await _client.PostAsync(uriPost, content);

                if (!response.IsSuccessStatusCode)
                {
                    throw new Exception($"Gagal menambah data: {response.StatusCode}");
                }
                else
                {
                    var resContent = await response.Content.ReadAsStringAsync();

                    userProfile = JsonConvert.DeserializeObject <UserProfile>(resContent);
                    return(userProfile);
                }
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
示例#13
0
        public ActionResult Login(UserLoginView userLogin)
        {
            if (ModelState.IsValid)
            {
                string passwordEncrypted = Crypto.crypto.GenerateSHA256String(userLogin.Password);
                var    v = db.Utilizador.Where(u => u.nome_utilizador == userLogin.Username && u.senha_utilizador == passwordEncrypted);

                if (v != null)
                {
                    //Criar objeto que passe toda informação session
                    try
                    {
                        Session["username"] = v.First().nome_utilizador;
                        Session["Id"]       = v.First().id_utilizador;
                        Session["Tipo"]     = v.First().id_tipo;
                        FormsAuthentication.SetAuthCookie(v.First().nome_utilizador, false);
                    }
                    catch (InvalidOperationException e) {
                        TempData["errorMessage"] = "Email e/ou password erradas! Tente novamente";
                        return(View("Error", new HandleErrorInfo(new Exception("Email e/ou password erradas! Tente novamente"), "Utilizadors", "Login")));
                    }
                    return(RedirectToAction("Index", "Relatorios"));
                }
            }

            return(View());
        }
示例#14
0
        public async Task LoginUser_ShouldRetunLoginFail(CommandResult <UserLoginResponse> result)
        {
            //Arrange
            var request = new UserLoginView();

            request.Email    = "*****@*****.**";
            request.Password = "******";

            result.Payload = new UserLoginResponse();
            result.ValidationResult.Errors.Add(new ValidationFailure(string.Empty, "Invalid request"));

            _mediatorHandler.Setup(s => s.SendCommand <UserLoginCommand, UserLoginResponse>(It.IsAny <UserLoginCommand>())).ReturnsAsync(result);

            _sut = new AuthController(_mediatorHandler.Object);

            //Act
            var response = await _sut.Login(request);

            //Assert
            var responseAssert = new BadRequestObjectResultMap(response);

            var expectedErrors = new List <string> {
                "Invalid request"
            };

            responseAssert.IsInvalidRequest(expectedErrors);
        }
示例#15
0
 public ActionResult LogIn(UserLoginView ULV, string returnUrl)
 {
     if (ModelState.IsValid)
     {
         UserManager UM       = new UserManager();
         string      password = UM.GetUserPassword(ULV.LoginName);
         if (string.IsNullOrEmpty(password))
         {
             ModelState.AddModelError("", "Username atau Password salah!");
         }
         else
         {
             if (ULV.Password.Equals(password))
             {
                 FormsAuthentication.SetAuthCookie(ULV.LoginName, false);
                 return(RedirectToAction("Welcome", "Home"));
             }
             else
             {
                 ModelState.AddModelError("", "Password Salah!");
             }
         }
     }
     return(View(ULV));
 }
 public object View()
 {
     return(_userLoginView ?? (_userLoginView = new UserLoginView()
     {
         DataContext = this
     }));
 }
示例#17
0
        public ActionResult LogIn(UserLoginView ULV, string returnUrl)
        {
            CustomMembershipProvider cs = new CustomMembershipProvider();

            if (ModelState.IsValid && cs.ValidateUser(ULV.LoginName, ULV.Password))
            {
                UserManager UM       = new UserManager();
                string      password = UM.GetUserPassword(ULV.LoginName);

                if (string.IsNullOrEmpty(password))
                {
                    ModelState.AddModelError("", "The user login or password provided is incorrect.");
                }
                else
                {
                    if (Crypto.VerifyHashedPassword(password, ULV.Password))
                    {
                        FormsAuthentication.SetAuthCookie(ULV.LoginName, false);
                        return(RedirectToAction("Welcome", "Home"));
                    }
                    else
                    {
                        ModelState.AddModelError("", "The password provided is incorrect.");
                    }
                }
                string[] roless = UM.GetRolesForUser(ULV.LoginName);
            }

            // If we got this far, something failed, redisplay form
            return(View(ULV));
        }
 public ActionResult forgotPassword(UserLoginView user)
 {
     UserManager mgr = new UserManager();
     mgr.updateUserDetails(user.UHCLEmail, user.confirmPassword);
     TempData["Message"] = "Password updated successfully.";
     return RedirectToAction("LogIn", "Account");
 }
示例#19
0
        public async Task <UserView> LoginAsync(UserLoginView userLoginView)
        {
            UserView userView = null;
            var      client   = new RestClient(_loginServiceUrl);
            var      request  = new RestRequest("api/login", Method.POST);

            request.AddHeader("content-type", "application/json");
            request.AddHeader("api-version", "1");
            request.AddParameter("application/json", JsonConvert.SerializeObject(userLoginView).ToString(), ParameterType.RequestBody);
            //client.ExecuteAsync(request, response =>
            //{
            //    var result = response;
            //});
            var response = await client.ExecuteAsync <object>(request);

            dynamic data = JsonConvert.DeserializeObject(response.Content);

            if ((bool)data.status)
            {
                string tempJson = JsonConvert.SerializeObject(data.result);
                userView = JsonConvert.DeserializeObject <UserView>(tempJson);
                Token    = userView.Jwt.Token;
            }

            return(userView);
        }
示例#20
0
        //[AllowAnonymous]
        public IActionResult UserLogin(string returnUrl = null)
        {
            if (_currentUser.CurrentUser.UserRoleName.FirstOrDefault() == "User" && _currentUser.CurrentUser.Activation == true)
            {
                return(RedirectToAction("profile", "Profile"));
            }

            if (_currentUser.CurrentUser != null)
            {
                if (_currentUser.CurrentUser.UserRoleName.FirstOrDefault() != "Guest")
                {
                    if (Url.IsLocalUrl(returnUrl))
                    {
                        return(Redirect(returnUrl));
                    }
                }
            }
            if (_currentUser.CurrentUser.UserRoleName.FirstOrDefault() == UserRoleName.TicketingUser && _currentUser.CurrentUser.Activation == true)
            {
                return(RedirectToAction("TicketingView", "Home"));
            }


            //  else
            //  return RedirectToAction("Index", "Dashboard", new { Area = "Admin" });


            this.ViewData["ReturnUrl"] = returnUrl;
            UserLoginView model = new UserLoginView();

            model.returnUrl = returnUrl;
            return(View(model));
        }
示例#21
0
        public async Task <UserView> GetSystemUserAsync(UserLoginView userLoginView)
        {
            UserView SystemUser = null;

            SystemUser = await this.LoginAsync(userLoginView);

            return(SystemUser);
        }
示例#22
0
 public bool Login(UserLoginView user)
 {
     if (user.Password == "geakmh" && user.Username == "admin")
     {
         return(true);
     }
     return(false);
 }
示例#23
0
 public void LogoutToView()
 {
     DialogHelper.Context.Closing += (o, e) =>
     {
         UserLoginView view = new UserLoginView();
         view.Show();
     };
     // Close current window
     DialogHelper.Context.Close();
 }
        public async Task <CommonApiResponse <UserView> > Post([FromBody] UserLoginView userLoginView)
        {
            Client   identityClient = new Client(Config.IdentityServiceBaseUrl);
            UserView userView       = await identityClient.LoginAsync(userLoginView);

            if (userView == null)
            {
                return(CommonApiResponse <UserView> .Create(Response, System.Net.HttpStatusCode.BadRequest, false, null, "Kullanıcı bilgileri geçersiz."));
            }
            return(CommonApiResponse <UserView> .Create(Response, System.Net.HttpStatusCode.OK, true, userView, ""));
        }
示例#25
0
        public UserView Login(UserLoginView user)
        {
            bool isValidLogin = _customerService.CheckLogin(user);

            if (isValidLogin)
            {
                return(_customerService.getUser(user.Email));
            }

            return(null);
        }
示例#26
0
 public bool IsAdmin(UserLoginView userLogin)
 {
     foreach (var item in dal.GetUserLoginList())
     {
         if (userLogin.UserID == item.UserID)
         {
             return(item.IsAdmin);
         }
     }
     return(false);
 }
示例#27
0
        private void DisplayUserLoginView()
        {
            PageTitle.Text    = "registration";
            button.Visibility = Visibility.Collapsed;
            var userLoginView = new UserLoginView
            {
                UserName = "******"
            };

            userLoginView.Login += userLoginView_Login;
            ActiveView           = userLoginView;
        }
示例#28
0
        public JsonResult Index(UserLoginView userToCheck)
        {
            //User.Identity.Name отсюда доставешь инфу кто залогинен и показываешь ему инфу основанную на этом

            if (!ModelState.IsValid)
            {
                return(new JsonResult()
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new { IsSuccess = false }
                });
            }

            //using (RegistrationService registry = new RegistrationService(SignInManager))
            //{
            //    try
            //    {
            RegistrationService registry = new RegistrationService(SignInManager);
            var existedUser = registry.UserValid(userToCheck.Email, userToCheck.Password);

            if (existedUser != null)
            {
                SignInManager.PasswordSignIn(existedUser.UserName, userToCheck.Password, false, false);
                //SignInManager.SignOut();
                var asd = User.Identity.Name;

                return(new JsonResult()
                {
                    JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                    Data = new { IsSuccess = true }
                });
            }
            ;
            //}
            //catch
            //{
            //    return new JsonResult()
            //    {
            //        JsonRequestBehavior = JsonRequestBehavior.AllowGet,
            //        Data = new { IsSuccess = false}
            //    };


            //return View("Querylist", registry.UserQueries(userToCheck.Id));
            //}

            return(new JsonResult()
            {
                JsonRequestBehavior = JsonRequestBehavior.AllowGet,
                Data = new { IsSuccess = false }
            });
            //}
        }
示例#29
0
        public ActionResult FacebookCallback(string code)
        {
            var fb = new FacebookClient();

            try
            {
                dynamic result = fb.Post("oauth/access_token", new
                {
                    client_id     = "148384642407735",
                    client_secret = "25b570ffac6aae99ab8729f63ea3c757",
                    redirect_uri  = RediredtUri.AbsoluteUri,
                    code          = code
                });
                var accessToken = result.access_token;
                //Session["AccessToken"] = accessToken;
                fb.AccessToken = accessToken;
                // to get all user data from url
                dynamic me    = fb.Get("me?fields=link,first_name,currency,last_name,email,gender,locale,timezone,verified,picture,age_range");
                string  email = me.email;
                TempData["email"]      = me.email;
                TempData["first_name"] = me.first_name;
                TempData["lastname"]   = me.last_name;
                //TempData["picture"] = me.picture.data.url;
                //FormsAuthentication.SetAuthCookie(email, false);

                #region chick if User email is exist or not

                var user = _userRepository.GetUserByEmail(email);
                if (user != null)
                {
                    UserLoginView userLogIn = new UserLoginView()
                    {
                        Email = email,
                    };
                    return(View("UserLogin", userLogIn));
                }
                else
                {
                    UserRegisterModel userRegister = new UserRegisterModel()
                    {
                        Email = me.email,
                        Name  = me.first_name,
                    };
                    return(View("RegisterUser", userRegister));
                }
                #endregion
            }
            catch
            {
                return(RedirectToAction("Index", "Home"));
            }
        }
示例#30
0
        public bool Validate(UserLoginView view)
        {
            if (!Validate(view.Username, view.Password))
            {
                return(false);
            }

            var hashPassword = this.hashService.Hash(view.Password);

            return(this.cotnext.Users
                   .Any(u => u.Username == view.Username &&
                        u.Password == hashPassword));
        }
        public async Task <IActionResult> Login([FromBody] UserLoginView view)
        {
            try
            {
                var user = await _service.Login(view.Email, view.Password);

                return(Ok(user.ToPrivateDto()));
            }
            catch (Exception e)
            {
                return(BadRequest(e.Message));
            }
        }
示例#32
0
        public ActionResult LogIn(UserLoginView ULV, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                UserRepository UM = new UserRepository();
                var CurrUSer = UM.AuthenticateUser(ULV.Email, ULV.Password);
                if ((bool)CurrUSer.IsLoginSuccess)
                {
                    FormsAuthentication.SetAuthCookie(ULV.Email, false);
                    var role = CurrUSer.Role;
                    return RedirectToAction("DashBoard", role);
                }
                else if (!(bool)CurrUSer.IsLoginSuccess)
                {
                    ModelState.AddModelError("", "The user login or password provided is incorrect.");
                    return View(ULV);
                }
                else
                    return View(ULV);

            }
            else
                return View();
        }