public async Task <ActionResult> Trust(LoginModel login)
        {
            string domain = login.UserName.Split('@')[1];

            InitSTS(domain);
            //validate identity
            var user = await LoginValidate.ValidateAsync(login, HttpRuntime.Cache);

            if (!user.IsValid)
            {
                Response.StatusCode        = (int)HttpStatusCode.Forbidden;
                Response.StatusDescription = HttpStatusCode.Forbidden.ToString();
                return(null);
            }

            //TODO: Need WSTrust handler?

            var res = new ContentResult()
            {
                ContentType     = "text/html",
                ContentEncoding = Encoding.UTF8,
                Content         = ""
                                  //Content = Encoding.UTF8.GetString(stream.ToArray())
            };

            return(res);
        }
Exemplo n.º 2
0
 public IActionResult LoginProcess(LoginValidate myLogin)
 {
     if (ModelState.IsValid)
     {
         Users loginData = _context.users.SingleOrDefault(p => p.email == myLogin.login_email);
         if (loginData == null)
         {
             ModelState.AddModelError("login_email", "Email Address is not registered");
         }
         else if (loginData != null && myLogin.login_password != null)
         {
             var Hasher = new PasswordHasher <Users>();
             // Pass the user object, the hashed password, and the PasswordToCheck
             if (0 != Hasher.VerifyHashedPassword(loginData, loginData.password, myLogin.login_password))
             {
                 HttpContext.Session.SetInt32("UserID", loginData.id);
                 int?UserID = HttpContext.Session.GetInt32("UserID");
                 ViewBag.UserID = UserID;
                 return(RedirectToAction("Dashboard"));
             }
             else
             {
                 ModelState.AddModelError("login_password", "Incorrect password");
                 return(View("Index"));
             }
         }
         return(View("Index"));
     }
     // ViewBag.error = "LOL, Nice try!";
     // TempData["error"] = "LOL, try again!";
     return(View("Index"));
 }
Exemplo n.º 3
0
        public ActionResult Index(LoginValidate val)
        {
            if (ModelState.IsValid)
            {
                var model = new CustomDao();
                var res   = model.Login(val.UserName, val.Password);
                if (res)
                {
                    var user        = model.GetCustomer(val.UserName);
                    var userSession = new UserSession();
                    userSession.UserName = user.UserName;
                    Session.Add(Constant.USER_SESSION, userSession);
                    if (model.isAdmin(user))
                    {
                        return(RedirectToAction("Index", "AdminHome"));
                    }

                    return(RedirectToAction("Index", "Home", new { Area = "" }));
                }
            }
            else
            {
                ModelState.AddModelError("", "email or password is not correct");
            }

            return(View());
        }
        public LoginValidate SignIn(string userName, [FromBody] UserDetail usr)// userName, string pwd, [Optional] string accType)
        {
            Login         db = new Login();
            LoginValidate lv = new LoginValidate();
            UserDetail    u  = db.SignIn(userName);

            if (u == null)
            {
                lv.loginStatus = -1; //User Does not Exist
                lv.accType     = "";
                lv.token       = "";
            }

            else
            {
                if (u.password == usr.password)
                {
                    if (u.role == "PM" && u.pmLoginStatus == false)
                    {
                        lv.loginStatus = 1; // login Successful
                        lv.accType     = u.role;
                        lv.token       = t.Encode(u.userName);
                        db.ChangeStatus(u.userName, "PM");
                    }
                    else if (u.role == "ET" && u.etLoginStatus == false)
                    {
                        lv.loginStatus = 1; // login Successful
                        lv.accType     = u.role;
                        lv.token       = t.Encode(u.userName);
                        db.ChangeStatus(u.userName, "ET");
                    }
                    else if (u.role == "BR") //broker ka check later
                    {
                        lv.loginStatus = 1;  // login Successful
                        lv.accType     = u.role;
                        lv.token       = t.Encode(u.userName);
                    }
                    else if (u.role == "PMT" && (u.pmLoginStatus == false || u.etLoginStatus == false))
                    {
                        lv.loginStatus = 1; // login Successful
                        lv.accType     = u.role;
                        db.ChangeStatus(u.userName, usr.role);
                        lv.token = t.Encode(u.userName);
                    }
                    else
                    {
                        lv.loginStatus = 2;//both trader and pm is already logged in at same time
                        lv.accType     = u.role;
                        lv.token       = "";
                    }
                }
                else
                {
                    lv.loginStatus = 0; // wrong Password
                    lv.accType     = u.role;
                    lv.token       = "";
                }
            }
            return(lv);
        }
        public LoginValidate ForgotPassword(string userName, [FromBody] UserDetail usr)//string userName,string answer)
        {
            Login         db = new Login();
            LoginValidate lv = new LoginValidate();
            UserDetail    u  = db.SignIn(userName);

            if (u == null)
            {
                lv.loginStatus = -1; //User Does not Exist
                lv.accType     = "";
                lv.token       = "";
            }
            else
            {
                string ans = db.ForgotPassword(userName);
                if (usr.securityAnswer == ans)
                {
                    lv.loginStatus = 1; // Correct Answer
                    lv.accType     = u.role;
                    db.ChangeStatus(u.userName, usr.role);
                    lv.token = t.Encode(u.userName);
                }
                else
                {
                    lv.loginStatus = 0; // wrong Answer
                    lv.accType     = u.role;
                    lv.token       = "";
                }
            }

            return(lv);
        }
Exemplo n.º 6
0
        public ActionResult GetEmailValidateCode(LogInModel model, string ValidateCode, string Option = "administartor")
        {
            bool isValidateForSend = false;
            bool sendIsOk          = false;

            //发送验证码
            ICreateEmail sendEmail = new CreateEnail();
            IGetEntity   getEntity = new GetEntity();
            //创建四位随机码
            String validateCode = CreateValidateCode.CreateValidateCodes();

            try
            {
                if (model.Account == null || model.Password == null)
                {
                    return(JavaScript(""));
                }
                Session["Administartor"] = validateCode;
                ILoinValidate log = new LoginValidate();
                if (sendIsOk == false && log.ValidateAccount(model, option: Option))
                {
                    var entity = getEntity.GetEntityForKey(model.Account,
                                                           accountSchoolDal);
                    sendIsOk = sendEmail.SeendEmail(entity.AdministratorAccount, entity.CreateAdminitratorDetialDatas.Email,
                                                    validateCode, "登陆验证");
                }
            }
            catch (Exception e)
            {
                isValidateForSend = false;
            }
            if (sendIsOk)
            {
                var createCookie = new CreateCooks();
                //创建Cookie
                var cookie = createCookie.CreateCooki(5);
                HttpContext.Response.Cookies.Add(cookie);
                isValidateForSend = true;
            }
            if (isValidateForSend)
            {
                var str = CreateJavaScript.CreateJS(5);
                return(JavaScript(str));
            }
            return(new HttpStatusCodeResult(400));
        }
        public LoginValidate SignUp([FromBody] UserDetail usr)
        {
            Login         db = new Login();
            LoginValidate lv = new LoginValidate();
            UserDetail    u  = db.SignIn(usr.userName);

            if (u != null)
            {
                lv.loginStatus = -1; //User already Exist
                lv.accType     = "";
                lv.token       = "";
            }
            else
            {
                db.SignUp(usr);
                lv.loginStatus = 1; //Signup Successful
                lv.accType     = "";
                lv.token       = "";
            }
            return(lv);
        }
 public IActionResult Login(LoginValidate user)
 {
     if (ModelState.IsValid)
     {
         if (!_context.Users.Any(u => u.Email == user.lEmail))
         {
             ViewBag.WrongEmail = "Email does not exist";
             return(View("Index"));
         }
         var lUser  = _context.Users.SingleOrDefault(u => u.Email == user.lEmail);
         var Hasher = new PasswordHasher <User>();
         if (0 != Hasher.VerifyHashedPassword(lUser, lUser.Password, user.lPassword))
         {
             HttpContext.Session.SetInt32("Id", lUser.Id);
             return(RedirectToAction("Dashboard"));
         }
         ViewBag.WrongPassword = "******";
         return(View("Index"));
     }
     ViewBag.WrongEmail    = "Email invalid";
     ViewBag.WrongPassword = "******";
     return(View("Index"));
 }
Exemplo n.º 9
0
        public ActionResult Login(LogInModel model, string ValidateCode, string Option = "administartor")
        {
            var sessionValidateCode = "";
            var XzPassword          = "";

            try
            {
                //登录逻辑代码
                #region 管理员登录代码

                sessionValidateCode = Session["Administartor"] == null ? "" : Session["Administartor"].ToString();
                if (!ComentBll.ExaminationEquals(ValidateCode, sessionValidateCode))
                {
                    ModelState.AddModelError("LogInError", "验证码不正确");
                    return(View());
                }
                ILoinValidate genlog = new LoginValidate();
                #region 管理员登录代码
                if (genlog.ValidateAccount(model, Option))
                {
                    var cookie = HttpContext.Request.Cookies["GetValidateTime"];
                    ComentBll.SettingExpiredCookie(HttpContext, cookie);
                    LoginModifySessionData(HttpContext);
                    Session["AdminUserLogin"] = model.Account;
                    //登录的账户与密码验证成功
                    return(Redirect("~/AdministartorsViews/Home"));
                }
                #endregion
                #endregion
            }
            catch (Exception e)
            {
                ModelState.AddModelError("LogInError", e.Message);
            }
            ModelState.AddModelError("LogInError", "账户名或密码不正确或检查您的登陆选项");
            return(View());
        }
        public ActionResult Login(LoginViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            LoginValidate valid = _securityHelper.LoginUser(model.Login, model.Password);

            if (valid == LoginValidate.Success)
            {
                FormsAuthentication.SetAuthCookie(model.Login, model.RememberMe);
                return(RedirectToAction("Index", "Home"));
            }
            if (valid == LoginValidate.NotApproved)
            {
                model.Message = "Not approved";
            }
            else
            {
                model.Message = "Not registered";
            }
            return(View(model));
        }
        public async Task <ActionResult> Login(LoginModel login)
        {
            if (login.UserName.IndexOf('@') < 0)
            {
                //incorrect format
                Session["Error"] = @"Enter your user ID in the format ""domain\user"" or ""user @domain"". ";
                return(RedirectToAction("Index", new { Request.Url.Query }));
            }

            string domain = login.UserName.Split('@')[1];

            InitSTS(domain);
            ValidationResponse user;

            try
            {
                //validate identity
                user = await LoginValidate.ValidateAsync(login, HttpRuntime.Cache);

                if (!user.IsValid)
                {
                    Session["Error"] = "Incorrect user ID or password. Type the correct user ID and password, and try again.";
                    return(RedirectToAction("Index", new { Request.Url.Query }));
                }
            }
            catch (Exception ex)
            {
                Common.Utils.AddLogEntry("Error during user authentication", System.Diagnostics.EventLogEntryType.Error, 0, ex);
                Session["Error"] = string.Format("An error occured during authentication ({0})", ex.Message);
                return(RedirectToAction("Index", new { Request.Url.Query }));
            }

            //identity validated
            string fullRequest = String.Format("{0}{1}{2}?{3}",
                                               Settings.HttpLocalhost,
                                               Settings.Port,
                                               Settings.WSFedStsIssue,
                                               Request.Url.Query
                                               );

            //todo:
            var immutableId = user.UserProperties.MasterGuid;
            //var immutableId = user.UserProperties.LocalGuid;

            SignInRequestMessage requestMessage = (SignInRequestMessage)WSFederationMessage.CreateFromUri(new Uri(fullRequest));

            //todo:
            requestMessage.Reply = string.Format("https://login.microsoftonline.com:443/login.srf?client-request-id={0}", Request.QueryString["client-request-id"]);

            ClaimsIdentity identity = new ClaimsIdentity(AuthenticationTypes.Federation);

            identity.AddClaim(new Claim("http://schemas.microsoft.com/LiveID/Federation/2008/05/ImmutableID", immutableId));
            identity.AddClaim(new Claim("http://schemas.xmlsoap.org/claims/UPN", user.UserProperties.Upn));
            //TODO: verify the source of this flag in ADFS
            //identity.AddClaim(new Claim("http://schemas.microsoft.com/ws/2012/01/insidecorporatenetwork", "true", typeof(bool).ToString()));

            ClaimsPrincipal principal = new ClaimsPrincipal(identity);

            SignInResponseMessage responseMessage = FederatedPassiveSecurityTokenServiceOperations.ProcessSignInRequest(requestMessage, principal, this.securityTokenService);

            MemoryStream stream = new MemoryStream();
            StreamWriter writer = new StreamWriter(stream, Encoding.UTF8);

            responseMessage.Write(writer);

            writer.Flush();
            stream.Position = 0;

            var res = new ContentResult()
            {
                ContentType     = "text/html",
                ContentEncoding = Encoding.UTF8,
                Content         = Encoding.UTF8.GetString(stream.ToArray())
            };

            return(res);
        }