public ValidationModel Register([Bind(Include = "FirstName,LastName,PhoneNumber,Email,Gender,State,Password,ConfirmPassword")] RegisterViewModel registerViewModel)
        {
            if (ModelState.IsValid)
            {
                if (_loginService.RegisterUser(registerViewModel, out var errorMessage))
                {
                    _loginService.AuthenticateUser(registerViewModel.Email);
                    return(new ValidationModel {
                        IsValid = true
                    });
                }
                else
                {
                    ModelState.AddModelError("", errorMessage);
                    return(new ValidationModel {
                        IsValid = false, ErrorMessage = errorMessage
                    });
                }
            }

            var errorList = ModelState.Values.SelectMany(m => m.Errors)
                            .Select(e => e.ErrorMessage)
                            .ToList();

            return(new ValidationModel {
                IsValid = false, ErrorMessage = errorList.First()
            });
        }
        private void btnLogin_Click(object sender, EventArgs e)
        {
            LoginService loginService = new LoginService();

            if (loginService.AuthenticateUser(txtUsername.Text, txtPassword.Text))
            {
                MenuStrip         menuStrip     = (MenuStrip)MdiParent.Controls["menuStrip1"];
                ToolStripMenuItem fileMenuItems = (ToolStripMenuItem)menuStrip.Items["fileToolStripMenuItem"];


                foreach (ToolStripItem item in fileMenuItems.DropDownItems)
                {
                    item.Enabled = true;
                }


                DialogResult result = MessageBox.Show("Login SuccessFull");
                if (result == DialogResult.OK)
                {
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("Incorrect Credentials");
            }
        }
        public ActionResult Login(string email, string password = "")
        {
            ActionResult actionResult = View("Login");

            if (email != null)
            {
                try
                {
                    var data = _loginService.AuthenticateUser(email);
                    if (data != null)
                    {
                        Session[AppConstants.UserIdSession]   = data.UserId;
                        Session[AppConstants.UserNameSession] = data.FirstName;
                        Session[AppConstants.UserTypeSession] = data.UserType;
                        LoadMenu(data.UserType);
                        actionResult = RedirectToAction("Index", "Student");
                    }
                    else
                    {
                        ViewBag.errorMessage = "Invalid credentilas";
                        actionResult         = View("Login");
                    }
                }catch (Exception ex)
                {
                    ViewBag.errorMessage = "Invalid credentilas";
                    actionResult         = View("Login");
                }
            }
            return(actionResult);
        }
Пример #4
0
        async Task <bool> LoginUser()
        {
            contentVm.IsBusy = true;

            bool   isValidUser = false;
            string userId      = txtUserId.Text != null?txtUserId.Text.Trim() : "";

            string pwd = txtPwd.Text != null?txtPwd.Text.Trim() : "";

            string site            = Settings.Site;
            bool   isValidAuthData = !(string.IsNullOrEmpty(userId) ||
                                       string.IsNullOrEmpty(pwd) ||
                                       string.IsNullOrEmpty(site));

            if (isValidAuthData)
            {
                isValidUser = await LoginService.AuthenticateUser(userId, pwd, site);

                if (!isValidUser)
                {
                    lblMsg.Text = "Incorrect User Name or Password!";
                }
                else
                {
                    lblMsg.Text = "";
                }
            }

            contentVm.IsBusy = false;
            return(isValidUser);
        }
Пример #5
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            LoginService loginservice = new LoginService();

            string inputUserName = txtUserName.Text;
            string inputPass     = txtPassWord.Text;


            if (loginservice.AuthenticateUser(inputUserName, inputPass))
            {
                ToolStripMenuItem filemenuitems;
                Form      parentform = this.MdiParent;
                MenuStrip ms         = (MenuStrip)parentform.Controls["menuStrip2"];
                filemenuitems = (ToolStripMenuItem)ms.Items["fileToolStripMenuItem"];
                MessageBox.Show("login success...");
                foreach (ToolStripItem item in filemenuitems.DropDownItems)
                {
                    if (item.Name == "addToolStripMenuItem" || item.Name == "searchToolStripMenuItem" || item.Name == "displayToolStripMenuItem")
                    {
                        item.Enabled = true;
                    }
                }

                DialogResult dialogueResult = MessageBox.Show("Login Successfull.....");
                if (dialogueResult == DialogResult.OK)
                {
                    this.Close();
                }
            }
            else
            {
                MessageBox.Show("Please enter correct credentials....");
            }
        }
Пример #6
0
        public ActionResult Index(LoginVm vm)
        {
            LoginService loginservice = new LoginService();

            if (!(loginservice.AuthenticateUser(vm.UserName, vm.UserPass)))
            {
                return(View(vm));
            }

            Session["user"] = vm.UserName;
            return(RedirectToAction(TempData["methodname"].ToString(), "Contact"));
        }
        public ActionResult Index(LoginVM vm)
        {
            LoginService loginService = new LoginService();

            if (loginService.AuthenticateUser(vm.UserName.ToLower(), vm.UserPassword.ToLower()))
            {
                Session["user"] = vm.UserName;
                Session.Timeout = 1;
                return(RedirectToAction(TempData["data"].ToString(), "Contact"));
            }
            return(View(vm));
        }
Пример #8
0
        public async Task <ActionResult> Login(LoginViewModel loginViewModel)
        {
            var loginBo = loginViewModel.Mapper(loginViewModel);
            var result  = await _loginService.AuthenticateUser(loginBo);

            if (result)
            {
                _loginService.SetFormsAuthentication(this.HttpContext, loginBo);
                return(Json(new { status = "redirect", redirectURL = loginViewModel.ReturnUrl ?? "/Home/DashBoard" }, JsonRequestBehavior.AllowGet));
            }
            return(Json(new { status = TransactionStatusEnum.error.ToString(), title = "Login Failed", message = "Invalid username or password" }, JsonRequestBehavior.AllowGet));
        }
Пример #9
0
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        LoginService loginservice  = new LoginService();
        string       inputusername = txtUserId.Text;
        string       inputpass     = txtPassword.Text;

        if (loginservice.AuthenticateUser(inputusername, inputpass))
        {
            Session["user"] = inputusername;
            Response.Redirect("Index.aspx");
        }
        lblValidUser.Text = "!enter a valid userid and password.....";
    }
Пример #10
0
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        LoginService loginservice = new LoginService();
        int          inputacntno  = Convert.ToInt32(txtUserId.Text);
        string       inputpass    = txtPassword.Text;

        if (loginservice.AuthenticateUser(inputacntno, inputpass))
        {
            Session["account"] = loginservice.acntHolder;
            Response.Redirect("Home.aspx");
        }
        lblValidUser.Text = "!enter a valid userid and password.....";
    }
Пример #11
0
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        string userName = txtUsername.Text;
        string password = txtPassword.Text;

        if (_loginService.AuthenticateUser(userName, password))
        {
            Session["user"] = txtUsername.Text;
            Session.Timeout = 1;

            Response.Redirect(Request.QueryString["RedirectTo"]);
        }
    }
Пример #12
0
        public IActionResult Login([FromBody] User login)
        {
            IActionResult response     = Unauthorized();
            var           loginService = new LoginService(_config);
            var           tokenString  = loginService.AuthenticateUser(login);

            if (tokenString != null)
            {
                _logger.LogInformation("User token created successfully");
                return(Ok(new { token = tokenString }));
            }
            _logger.LogError("Unauthorized user detected");
            return(Unauthorized(new { StatusCode = 401, message = "Invalid user" }));
        }
Пример #13
0
        public void AuthenticateUser_WrongPassword_ShouldReturnNull()
        {
            var context = new ApplicationDbContext(_testcs);
            var service = new LoginService(context, _config);
            var user    = new User()
            {
                UserName     = "******",
                PasswordHash = "Password",
            };

            var result = service.AuthenticateUser(user);

            Assert.That(result, Is.Null);
        }
Пример #14
0
        public void AuthenticateUser_CorrectPassword_ShouldReturnUser()
        {
            var context = new ApplicationDbContext(_testcs);
            var service = new LoginService(context, _config);
            var user    = new User()
            {
                UserName     = "******",
                PasswordHash = "haslo",
            };

            var result = service.AuthenticateUser(user);

            Assert.That(result, Is.TypeOf <User>());
        }
Пример #15
0
        public IActionResult Login([FromBody] Member login)
        {
            IActionResult response = Unauthorized();

            var user = _loginService.AuthenticateUser(login);

            if (user != null)
            {
                var tokenString = _loginService.GenerateJSONWebToken(user, _config);
                response = Ok(new { token = tokenString, username = user.username, id = user.Id });
            }

            return(response);
        }
Пример #16
0
        public ActionResult AlteraSenha(FormularioUsuarioViewModel vm)
        {
            using (LoginService loginService = new LoginService())
            {
                try
                {
                    loginService.AuthenticateUser(User.Email, vm.VerificacaoSenhaAlteracao);
                }
                catch (InternalException)
                {
                    return(Json(new { success = false, responseText = "Senha incorreta." }));
                }
            }

            usuarioRepository.Update(vm.Usuario);

            return(Json(new { success = true, responseText = "A sua senha foi alterada com sucesso." }));
        }
Пример #17
0
        public ActionResult Login(AutenticacaoViewModel vm)
        {
            using (LoginService loginService = new LoginService())
            {
                try
                {
                    HttpCookie ck = loginService.AuthenticateUser(vm.Email, vm.Senha);
                    Response.Cookies.Add(ck);
                }
                catch (InternalException inEx)
                {
                    ModelState.AddModelError("FalhaAutenticacao", inEx.Message);
                    return(View("AutenticacaoView", vm));
                }
            }

            return(RedirectToAction("Index", "BuscaProjetos"));
        }
Пример #18
0
    protected void btnLogin_Click(object sender, EventArgs e)
    {
        int    userAccount = Convert.ToInt32(txtUserAccount.Text);
        string password    = txtPassword.Text;

        if (_loginService.AuthenticateUser(userAccount, password))
        {
            Session["account"]       = txtUserAccount.Text;
            Session["AccountHolder"] = _loginService.Account;
            Session.Timeout          = 1;

            if (Request.QueryString["RedirectTo"] != null)
            {
                Response.Redirect(Request.QueryString["RedirectTo"]);
            }
            Response.Redirect("Home.aspx");
        }
    }