コード例 #1
0
        public ActionResult LogIn(LogInModel model, string returnUrl)
        {
            WebView.WebService._base myWebService;
            myWebService = new WebService._base();

            UserModel user;

            string password = Crypto.EncryptStringAES(model.Password);

            model.UserName = model.UserName.ToUpper();
            if (ModelState.IsValid)
            {
                user = myWebService.ValidateUser(model.UserName, model.Password);
                //user = myWebService.ValidateUser(model.UserName, password);
                if (user.IsValidUser)
                {
                    ////##  Add Cookie Method 1 ##////////////////
                    FormsAuthentication.SetAuthCookie(model.UserName, model.RememberMe);

                    Session["UserInfo"] = user;

                    string        role = "";
                    string        uAuditTrail;
                    List <string> roles = new List <string>();
                    Tools         tool  = new Tools();
                    using (Entities ctxData = new Entities())
                    {
                        var queryUser = (from p in ctxData.WV_USER
                                         where p.USERNAME.ToUpper() == model.UserName.ToUpper() || p.USERNAME.ToLower() == model.UserName.ToLower()
                                         select p).Single();

                        uAuditTrail = queryUser.USERNAME;

                        var queryUserRole = (from fx in ctxData.WV_GROUP
                                             join fxx in ctxData.WV_GRP_ROLE on fx.GRPNAME equals fxx.GRPNAME
                                             where fx.GRP_ID == queryUser.GROUPID
                                             select fxx).Single();
                        user.FullName = queryUser.FULL_NAME;
                        role          = queryUserRole.ROLENAME;
                    }

                    roles.Add(role);
                    string passPhrase = "preAuthpassword";
                    string username   = User.Identity.Name;
                    string url        = Encryptor.GetURL(passPhrase, "10.41.61.177", "8080", model.UserName, roles);
                    System.Diagnostics.Debug.WriteLine(url);

                    Session["ISP_INFO"]       = visionael + "/nrm/vfd/MainPage.iface" + url;
                    Session["ISP_LOGIN_INFO"] = url;
                    Session["JASPER"]         = "http://10.41.61.177:8080/jasperserver/j_spring_security_check?j_username=neps-user&j_password=nepsuser";

                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                        !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        myWebService.AddUserAudit(uAuditTrail);
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "The user name or password provided is incorrect.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }