コード例 #1
0
ファイル: AccountController.cs プロジェクト: wfguanhan/CDMIS
 public ActionResult LogOn(string control, string page)
 {
     Session["CurrentUser"] = null;
     LogOnModel LogOnModel = new LogOnModel();
     ViewData["controller"] = control;
     ViewData["actionResult"] = page;
     return View(LogOnModel);
 }
コード例 #2
0
ファイル: AccountController.cs プロジェクト: SimonTDY/CDMIS
        public ActionResult LogOn(LogOnModel LogOnModel, string control, string page)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var UserId = LogOnModel.UserId;
                    var Password = LogOnModel.Password;
                    var Type = "";
                    var EmailFlag = Regex.IsMatch(UserId, @"(^[-_A-Za-z0-9]+@([_A-Za-z0-9]+\.)+[A-Za-z0-9]{2,3}$)");
                    var PhoneFlag = Regex.IsMatch(UserId, @"(^1[3-8]\d{9}$)");
                    if (EmailFlag == true)
                    {
                        Type = "EmailAdd";
                    }
                    if (PhoneFlag == true)
                    {
                        Type = "PhoneNo";
                    }
                    if (Type != "")
                    {
                        UserId = _ServicesSoapClient.GetIDByInput(Type, UserId);
                    }
                    if (_ServicesSoapClient.CheckUserExist(UserId) == true)
                    {
                        if (_ServicesSoapClient.CheckPassword(UserId, Password) == 1)
                        {
                            var CurrentUser = new UserAndRole();
                            CurrentUser.UserId = UserId;
                            CurrentUser.UserName = _ServicesSoapClient.GetUserName(UserId);
                            //CurrentUser.Role = _ServicesSoapClient.GetClassByUserId(UserId);
                            var RoleList = _ServicesSoapClient.GetAllRoleMatch(UserId);
                            //var Role = RoleList.Tables[0].Rows[0]["RoleClass"];
                            var length = RoleList.Tables[0].Rows.Count;
                            string[] RoleClass = new string[length];
                            for (int i = 0; i < length; i++)
                            {
                                RoleClass[i] = RoleList.Tables[0].Rows[i]["RoleClass"].ToString();
                                if (RoleClass[i] == "Administrator")
                                {
                                    CurrentUser.Role = "Administrator";
                                }
                                else if (RoleClass[i] == "Doctor")
                                {
                                    CurrentUser.Role = "Doctor";
                                }
                            }
                            //CurrentUser.UserName = UserName;
                            CurrentUser.TerminalName = Dns.GetHostName();
                            string hostAddress = Request.ServerVariables.Get("Local_Addr").ToString();
                            if (hostAddress == "::1")
                            {
                                hostAddress = "127.0.0.1";
                            }
                            CurrentUser.TerminalIP = hostAddress;
                            CurrentUser.DeviceType = 1;

                            var ChangeLastLogOnTimeFlag = _ServicesSoapClient.UpdateLastLoginDateTime(CurrentUser.UserId, CurrentUser.UserName, CurrentUser.TerminalIP, CurrentUser.TerminalName, CurrentUser.DeviceType);
                            Session["CurrentUser"] = CurrentUser;
                            FormsAuthentication.SetAuthCookie(UserId, true);
                            if (control == null && page == null)
                            {
                                if (CurrentUser.Role == "Administrator")
                                {
                                    return RedirectToAction("Index", "Management");
                                }
                                else if (CurrentUser.Role == "Doctor")
                                {
                                    var ActivitionFlag = _ServicesSoapClient.GetActivatedState(UserId, "Doctor");
                                    if (ActivitionFlag == "0")
                                    {
                                        return RedirectToAction("PatientList", "DoctorHome");
                                    }
                                    else
                                    {
                                        return RedirectToAction("Activition", "Account");
                                    }

                                }
                                else
                                {
                                    ModelState.AddModelError("errorConnection", "该用户没有权限登录本系统");
                                    return View();
                                }
                                //switch (CurrentUser.Role)
                                //{
                                //    case "Administrator": return RedirectToAction("Index", "Dict");
                                //    case "Doctor": return RedirectToAction("PatientList", "DoctorHome");
                                //    //case "Patient": return RedirectToAction("HealthParameters", "PatientHome");
                                //    default: ModelState.AddModelError("", "该用户没有权限登录本系统");
                                //        return View();
                                //}
                            }
                            else
                            {
                                return RedirectToAction(page, control);
                            }
                        }
                        else
                        {
                            ModelState.AddModelError("errorPassword", "密码错误,请重新输入密码");
                            return View(LogOnModel);
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("errorUserId", "用户不存在,请重新输入用户ID");
                        return View(LogOnModel);
                    }
                }
                else
                {
                    return View(LogOnModel);
                }

            }
            catch (Exception)
            {
                ModelState.AddModelError("errorConnection", "数据库连接失败");
                return View(LogOnModel);
            }
        }