Esempio n. 1
0
        public JsonResponse <UserMasterDTO> UserMasterLogin(UserAccountDTO u)
        {
            ActivityLog.SetLog("[Started] UserMasterLogin.", LogLoc.INFO);
            JsonResponse <UserMasterDTO> response = new JsonResponse <UserMasterDTO>();
            UserMasterDTO UserMasterDTO;

            if (!String.IsNullOrEmpty(u.email))
            {
                UserMasterDTO = UserBusinessInstance.UserLogin(u.email, u.password);

                response.SingleResult = UserMasterDTO != null ? UserMasterDTO : null;
                response.StatusCode   = UserMasterDTO != null ? "200" : "500";
                response.IsSuccess    = UserMasterDTO != null ? true : false;
                response.Message      = UserMasterDTO != null ? "Successfully loggedin" : Messages.LoginWrongPassword + " : Incorrect Password!";;;
            }
            else
            {
                response.SingleResult = null;
                response.StatusCode   = "500";
                response.IsSuccess    = false;
                response.Message      = "Username or Email can not be empty.";
            }
            ActivityLog.SetLog("[Finished] UserMasterLogin.", LogLoc.INFO);
            return(response);
        }
        public JsonResponse <UserMasterBO> Login(string email, string password)
        {
            JsonResponse <UserMasterBO> response = new JsonResponse <UserMasterBO>();
            UserMasterBO user = UserBusinessInstance.UserLogin(email, password); //.Where(x => x.cemailaddress == email && x.cpassword == password).FirstOrDefault();

            response.SingleResult = user;
            return(response);
        }
Esempio n. 3
0
        public ActionResult Login(string email, string password)
        {
            UserMasterBO user = UserBusinessInstance.UserLogin(email, password); //.Where(x => x.cemailaddress == email && x.cpassword == password).FirstOrDefault();

            if (user != null)
            {
                ViewBag.LoginMessage = "User Logged In successfully!";
                USERPROFILE          = user;
                WelcomeUser(user.UserID);
                return(RedirectToAction("Index", "Home"));
            }
            else
            {
                ViewBag.Message = "You are not authorized to login, please contact your administrator";
                Response.Redirect("~/Account/UnAuthorizedUser", true);
                return(View("UnAuthorizedUser", "Account"));
            }
        }
Esempio n. 4
0
        public override void OnAuthorization(HttpActionContext actionContext)
        {
            if (string.IsNullOrEmpty(actionContext.Request.Headers.Authorization?.Parameter))
            {
                actionContext.Response = actionContext.Request.CreateResponse(HttpStatusCode.Unauthorized);
                if (actionContext.Response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    actionContext.Response.Headers.Add("WWW-Authenticate", string.Format("Basic realm=\"{0}\"", Realm));
                }
            }
            else
            {
                string   authenticationToken        = actionContext.Request.Headers.Authorization.Parameter;
                string   decodedAuthenticationToken = Encoding.UTF8.GetString(Convert.FromBase64String(authenticationToken));
                string[] usernamePasswordArray      = decodedAuthenticationToken.Split(':');
                string   username = usernamePasswordArray[0];
                string   password = usernamePasswordArray[1];
                var      user     = UserBusinessInstance.UserLogin(username, password);
                if (user != null)
                {
                    var identity = new GenericIdentity(username);
                    var roles    = SecurityBusinessInstance.GetUserRoleNames(user.UserID);
                    identity.AddClaim(new Claim("Email", user.Email));
                    identity.AddClaim(new Claim(ClaimTypes.Name, user.FirstName + " " + user.LastName));
                    identity.AddClaim(new Claim(ClaimTypes.Role, roles[0]));
                    identity.AddClaim(new Claim("ID", Convert.ToString(user.UserID)));

                    IPrincipal principal = new GenericPrincipal(identity, roles);
                    Thread.CurrentPrincipal = principal;
                    if (HttpContext.Current != null)
                    {
                        HttpContext.Current.User = principal;
                    }
                }
                else
                {
                    actionContext.Response = actionContext.Request
                                             .CreateResponse(HttpStatusCode.Unauthorized);
                }
            }
        }