コード例 #1
0
ファイル: LoginController.cs プロジェクト: basharnaim/ERP
        public ActionResult CPanel(string userId, string password, string returnUrl)
        {
            string workStationIP = GetLocalIpAddress(System.Web.HttpContext.Current);
            var    userInfo      = _userService.GetControlUser(userId, password);

            if (!string.IsNullOrEmpty(userInfo?.Id))
            {
                string basicTicket = LoginIdentity.CreateBasicTicket(
                    userInfo.Id,
                    "",
                    null,
                    "",
                    null,
                    workStationIP,
                    true,
                    true);
                string[] roles      = _userService.GetUserRoles(userId);
                string   roleTicket = LoginIdentity.CreateRoleTicket(roles);
                FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, FormsAuthentication.FormsCookieName, DateTime.Now, DateTime.Now.AddMinutes(720), true, basicTicket);
                string encTicket = FormsAuthentication.Encrypt(authTicket);
                HttpContext.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
                HttpContext.Application["BasicTicket" + userId] = basicTicket;
                HttpContext.Application["RoleTicket" + userId]  = roleTicket;
                return(RedirectToAction("Index", "Home", new { area = "CPanel" }));
            }
            ViewBag.Message = "User name or password is invalid!";
            return(View());
        }
コード例 #2
0
 private bool ValidateIdentity(LoginIdentity identity)
 {
     if (string.IsNullOrEmpty(identity.Account))
     {
         //WriteErrorTip(this.account.ClientID, "请输入用户名");
         return(false);
     }
     if (identity.Account.Length > 50)
     {
         //WriteErrorTip(this.account.ClientID, "用户名超出最大长度,请重新输入");
         return(false);
     }
     if (string.IsNullOrEmpty(identity.Password))
     {
         //WriteErrorTip(this.password.ClientID, "请重新输入密码");
         return(false);
     }
     //if ((!IsTrustAccessor) && (string.IsNullOrWhiteSpace(txtVerificationCodeStr) || ImageVerifier1.Text != txtVerificationCodeStr))
     //{
     //    this.hiddenPwd.Value = identity.Password;
     //    this.Verfiy.Text = "";
     //    WriteErrorTip(this.Verfiy.ClientID, "验证码错误,请重新输入");
     //    return false;
     //}
     return(true);
 }
コード例 #3
0
        public LoginResultObject GetUserTokenII(string loginName, string password)
        {
            LoginResultObject result = null;

            HttpCookieHelper.ClearCurrentAuthCooike();
            var identity = new LoginIdentity(loginName, password, GetSSOConfigSettings.Informations["SystemCode"].Value);

            if (ValidateIdentity(identity))
            {
                using (var channel = ChannelFactory.Create <ILogin>(ServiceAddress))
                {
                    result = channel.Channel.Login(RemotingToken.Token, identity);
                }
            }
            return(result);
        }
コード例 #4
0
ファイル: Global.asax.cs プロジェクト: basharnaim/ERP
        ///-------------------------------------------------------------------------------------------------
        /// <summary>   Event handler. Called by Application for acquire request state events. </summary>
        ///
        /// <remarks>   Rafiqul Islam, 12/2/2015. </remarks>
        ///
        /// <param name="sender">   Source of the event. </param>
        /// <param name="e">        Event information. </param>
        ///-------------------------------------------------------------------------------------------------

        protected void Application_AcquireRequestState(object sender, EventArgs e)
        {
            try
            {
                HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];
                if (authCookie != null && authCookie.Value != "")
                {
                    FormsAuthenticationTicket ticket   = FormsAuthentication.Decrypt(authCookie.Value);
                    LoginIdentity             identity = new LoginIdentity(ticket.UserData);
                    var basicTicket = Application["BasicTicket" + identity.Name];
                    var roleTicket  = Application["RoleTicket" + identity.Name];
                    if (basicTicket != null && roleTicket != null && basicTicket.ToString() == ticket.UserData)
                    {
                        identity.SetRoles(roleTicket.ToString());
                        LoginPrincipal principal = new LoginPrincipal(identity);
                        HttpContext.Current.User = principal;
                        Thread.CurrentPrincipal  = principal;
                        FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, FormsAuthentication.FormsCookieName, DateTime.Now, DateTime.Now.AddMinutes(720), ticket.IsPersistent, ticket.UserData);
                        string encTicket = FormsAuthentication.Encrypt(authTicket);
                        HttpContext.Current.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
                        return;
                    }
                    authCookie.Expires = DateTime.Now.AddDays(-1);
                    HttpContext.Current.Response.Cookies.Add(authCookie);
                    Application["BasicTicket" + identity.Name] = null;
                    Application["RoleTicket" + identity.Name]  = null;
                    if (HttpContext.Current.Request.Path.ToUpper().StartsWith("/CPANEL"))
                    {
                        HttpContext.Current.Response.Redirect("/Login/cpanel");
                    }
                    if (HttpContext.Current.Request.Path.ToUpper().StartsWith("/APanel"))
                    {
                        HttpContext.Current.Response.Redirect("/Login");
                    }
                }
                else
                {
                    //HttpContext.Current.Response.Redirect("http://localhost:44372");  // = //new RedirectToRouteResult(new RouteValueDictionary { { "action", "Index" }, { "controller", "Login" } });
                    //HttpContext.Current.RewritePath("http://localhost:44372/");
                }
            }
            catch (Exception ex)
            {
                var fail = ex.Message;
                FormsAuthentication.SignOut();
            }
        }
コード例 #5
0
ファイル: LoginController.cs プロジェクト: basharnaim/ERP
 public ActionResult Index(string userId, string password, string returnUrl)
 {
     try
     {
         string workStationIp = GetLocalIpAddress(System.Web.HttpContext.Current);
         var    userInfo      = _userService.Login(userId, password);
         if (!string.IsNullOrEmpty(userInfo?.Id))
         {
             var userGroup = _userGroupService.GetById(userInfo.UserGroupId);
             var company   = new Company();
             var branch    = new Branch();
             if (!string.IsNullOrEmpty(userGroup?.Id))
             {
                 company = _userService.GetCompanyInfo(userGroup.CompanyId);
                 branch  = _userService.GetBranchInfo(userGroup.BranchId);
             }
             string[] roles       = _userService.GetUserRoles(userId);
             string   basicTicket = LoginIdentity.CreateBasicTicket(
                 userInfo.UserId,
                 company?.Id,
                 company?.Name,
                 branch?.Id,
                 branch?.Name,
                 workStationIp,
                 userInfo.SysAdmin,
                 true);
             string roleTicket = LoginIdentity.CreateRoleTicket(roles);
             FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(1, FormsAuthentication.FormsCookieName, DateTime.Now, DateTime.Now.AddMinutes(720), true, basicTicket);
             string encTicket = FormsAuthentication.Encrypt(authTicket);
             HttpContext.Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName, encTicket));
             HttpContext.Application["BasicTicket" + userId] = basicTicket;
             HttpContext.Application["RoleTicket" + userId]  = roleTicket;
             if (userInfo.SysAdmin)
             {
                 return(RedirectToAction("Index", "Home", new { area = "APanel" }));
             }
             return(RedirectToAction("Index", "Home", new { area = "" }));
         }
         ViewBag.Message = "User Id and password does not match or you are not a valid user...";
         return(View());
     }
     catch (Exception ex)
     {
         ViewBag.Message = ex.Message;
         return(View());
     }
 }
コード例 #6
0
        public async Task <IActionResult> Login(LoginIdentity model)
        {
            string error = " Login Failed Please retry!!";

            if (ModelState.IsValid)
            {
                var result = await signInManager.PasswordSignInAsync(
                    model.Email, model.Password, model.RememberMe, false);

                if (result.Succeeded)
                {
                    string Message = "Login successfully!!";
                    return(this.Ok(new { Message }));
                }

                ModelState.AddModelError(string.Empty, "Invalid Login Attempt");
            }

            return(this.BadRequest(new { error }));
        }
コード例 #7
0
ファイル: LoginController.cs プロジェクト: basharnaim/ERP
        public ActionResult Logout(string road)
        {
            HttpCookie authCookie = Request.Cookies[FormsAuthentication.FormsCookieName];

            if (authCookie != null && authCookie.Value != "")
            {
                FormsAuthenticationTicket ticket   = FormsAuthentication.Decrypt(authCookie.Value);
                LoginIdentity             identity = new LoginIdentity(ticket.UserData);
                authCookie.Expires = DateTime.Now.AddDays(-1);
                HttpContext.Response.Cookies.Add(authCookie);
                HttpContext.Application["BasicTicket" + identity.Name] = null;
                HttpContext.Application["RoleTicket" + identity.Name]  = null;
            }
            switch (road)
            {
            case "cpanel":
                return(Redirect("/Login/CPanel"));

            default:
                return(Redirect("/Login"));
            }
        }