Beispiel #1
0
 /// <summary>
 /// AuthenticateUser used for authenticating an user.
 /// </summary>
 /// <param name="userName">User name provided by user.</param>
 /// <param name="password">Password provided by user.</param>
 /// <returns></returns>
 public int AuthenticateUser(string userName, string password)
 {
     try
     {
         Authenticate auth = new Authenticate();
         return(auth.AuthenticateUser(userName, password));
     }
     catch (Exception ex)
     {
         throw LogWcfError(ex, "Error authenicating an user", Framework.Enums.Enums.ErrorLevel.ERROR, ErrorCodes.ErrorCodes.ErrorAuthenticateUser);
     }
 }
        protected void btnLogin_Click(object sender, EventArgs e)
        {
            string username = txtUsername.Text;
            string password = txtPassword.Text;
            bool   allowAccess;

            Authenticate authenticateInstance = new Authenticate();

            allowAccess = authenticateInstance.AuthenticateUser(username, password);

            if (allowAccess)
            {
                Session["user"] = username;
                //Response.Redirect("Home.aspx");
                FormsAuthentication.RedirectFromLoginPage(username, false);
            }
            else
            {
                lblErrorLogin.Text = "Invalid username or password";
            }
        }
        public ActionResult Post([FromBody] UserLogIn user)
        {
            try
            {
                var userResult = _userService.GetUser(user);

                if (userResult == null)
                {
                    return(BadRequest(new { message = "Email or password is incorrect" }));
                }
                var response = Authenticate.AuthenticateUser(userResult, _appSettings);
                return(Ok(response));
            }
            catch (Exception ex)
            {
                var errorModel = new Status()
                {
                    Message = ex.Message
                };
                Log.Error(ex, ex.Message);
                return(StatusCode(500, errorModel));
            }
        }