예제 #1
0
        public ActionResult Register(RegisterModel model)
        {
            if (Microsoft.Web.Helpers.ReCaptcha.Validate(privateKey: ""))               //enter recaptcha private key here!
            {
                if (ModelState.IsValid)
                {
                    // Attempt to register the user
                    var b = Warehouse.Register(model.AccountName, HashHelper.GetMd5Hash(model.Password), model.Username, model.Usersurname, model.Institution, int.Parse(model.Course), model.Email);
                    if (b.Type == ErrorType.Ok)
                    {
                        if (CustomPrincipal.Login(model.AccountName, model.Password, false))
                        {
                            return(RedirectToAction("Index", "Home"));
                        }
                        else
                        {
                            ModelState.AddModelError("", "Неправильный логин или пароль.");
                        }
                    }
                    else
                    {
                        // todo make error message
                        ModelState.AddModelError("", b.Message);                        //"Some error while registration"/*ErrorCodeToString(createStatus)/**/);
                    }
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
예제 #2
0
        public ActionResult Login(Usuario model, string returnUrl)
        {
            if (model != null)
            {
                //probamos si el usuario y la password son validos
                if (CustomPrincipal.Login(model.login, model.password, model.Recordar))
                {
                    //si son validos, retornamos a la pagina de la que viniesemos
                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/", StringComparison.CurrentCulture) && !returnUrl.StartsWith("//", StringComparison.CurrentCulture) && !returnUrl.StartsWith("/\\", StringComparison.CurrentCulture))
                    {
                        return(Redirect(returnUrl));
                    }

                    ////var cus = (CustomIdentity)System.Web.HttpContext.Current.User.Identity;

                    //distinguimos entre un tipo de usuario y otro y redirigimos
                    if (System.Web.HttpContext.Current.User.IsInRole("SuperAdmin"))
                    {
                        return(RedirectToAction("Index", "GestionUsuarios"));
                    }

                    return(RedirectToAction("Index", "home"));
                }
                //si no son validos, datos incorrectos
                ModelState.AddModelError("", "Datos incorrectos");
            }
            return(View(model));
        }
예제 #3
0
        public ActionResult LogOn(LogOnModel model, string returnUrl)
        {
            if (ModelState.IsValid)
            {
                if (CustomPrincipal.Login(model.UserName, model.Password, model.RememberMe))
                {
                    if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                        !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                    {
                        return(Redirect(returnUrl));
                    }
                    else
                    {
                        return(RedirectToAction("Index", "Home"));
                    }
                }
                else
                {
                    ModelState.AddModelError("", "Неправильный логин или пароль.");
                }
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
예제 #4
0
        public ActionResult Login(LoginModel model, string returnUrl)
        {
            //if (ModelState.IsValid && WebSecurity.Login(model.UserName, model.Password, persistCookie: model.RememberMe))
            //{
            //    return RedirectToLocal(returnUrl);
            //}

            //// If we got this far, something failed, redisplay form
            //ModelState.AddModelError("", "The user name or password provided is incorrect.");
            if (ModelState.IsValid)
            {
                string code = Request["code"];
                if (Session["__VCode"] == null)
                {
                    ModelState.AddModelError("", "验证码不正确");
                    return(View(model));
                }
                if (code != Session["__VCode"].ToString())
                {
                    ModelState.AddModelError("", "验证码不正确");
                    return(View(model));
                }
                Core.PaginationInfo paging = new Core.PaginationInfo();
                IList <User>        users  = iuser.Get(null, model.UserName, null, null, null, null, null, null, null, null, 1, 0, null, out paging);
                if (users.Count > 0)
                {
                    User user = users[0];
                    if (user.Password == model.Password)
                    {
                        ICustomPrincipal cp = new CustomPrincipal();
                        cp.Login(model.UserName, user.ID.ToString(), true);
                        user.Ip            = null;
                        user.Lastlogintime = DateTime.Now;
                        //user.IsLogin = true;
                        bool isupdate = iuser.Update(user);


                        if (user.Role != 0)
                        {
                            if (!string.IsNullOrEmpty(returnUrl))
                            {
                                return(Redirect(returnUrl));
                            }
                            WriteLog(user.Username + " 登录系统");
                            return(RedirectToAction("Index", "Home"));
                        }
                        else
                        {
                            WriteLog(user.Username + " 登录系统");
                            return(RedirectToAction("usermanager", "admin"));
                        }
                    }
                }

                ModelState.AddModelError("", "用户名密码错误");
            }
            return(View(model));
        }
예제 #5
0
        protected override void OnAuthorization(AuthorizationContext filterContext)
        {
            base.OnAuthorization(filterContext);
            HttpCookie cookie = Request.Cookies[FormsAuthentication.FormsCookieName];

            if (cookie != null)
            {
                FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);
                var newTicket = FormsAuthentication.RenewTicketIfOld(ticket);
                if (newTicket != null && newTicket.Expiration != ticket.Expiration)
                {
                    string encryptedTicket = FormsAuthentication.Encrypt(newTicket);

                    cookie      = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);
                    cookie.Path = FormsAuthentication.FormsCookiePath;
                    Response.Cookies.Add(cookie);
                }
                CustomPrincipal.Login(ticket.UserData);
            }
        }
예제 #6
0
        public ActionResult Index()
        {
            //ViewBag.Message = "Modify this template to jump-start your ASP.NET MVC application.";
            string userid = Request["uid"];

            if (!string.IsNullOrEmpty(userid))
            {
                User user = iuser.Get(Guid.Parse(userid));
                if (user != null)
                {
                    ICustomPrincipal cp = new CustomPrincipal();
                    cp.Login(user.Username, user.ID.ToString(), true);
                    user.Ip            = GetClientIP();
                    user.Lastlogintime = DateTime.Now;
                    user.IsLogin       = true;
                    bool isupdate = iuser.Update(user);
                }
            }

            return(RedirectToAction("index", "share"));
        }
예제 #7
0
        public ActionResult Login(LoginViewModel viewModel)
        {
            // Ensure we have a valid viewModel to work with
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var _modelAutenticacao = CustomPrincipal.Login(viewModel.Email, viewModel.Senha, viewModel.LembreMe);

            if (_modelAutenticacao.IsAuthenticated)
            {
                return(RedirectToLocal(viewModel.ReturnUrl));
            }

            // No existing user was found that matched the given criteria
            ModelState.AddModelError("", _modelAutenticacao.MensagemLogin);

            // If we got this far, something failed, redisplay form
            return(View(viewModel));
        }
예제 #8
0
        public ActionResult Login(LoginRequest request)
        {
            Account_Service account_Service = new Account_Service();
            LoginResponse   response        = account_Service.Login(request);

            if (response.IsSucceed)
            {
                CustomPrincipal.Login(response);
                if (response.UserView.RoleName == Role.User.ToString())
                {
                    return(RedirectToUserHomePage());
                }
                if (response.UserView.RoleName == Role.Developer.ToString() || response.UserView.RoleName == Role.Senior.ToString())
                {
                    return(RedirectToDeveloperHomePage());
                }
                if (response.UserView.RoleName == Role.Admin.ToString())
                {
                    return(RedirectToAdminHomePage());
                }
            }
            return(View(response.Message));
        }
예제 #9
0
        public ActionResult Register(RegisterModel model, string refer)
        {
            if (ModelState.IsValid)
            {
                // Attempt to register the user
                string code = Request["code"];
                if (Session["__VCode"] == null)
                {
                    return(View(model));
                }
                if (code != Session["__VCode"].ToString())
                {
                    ModelState.AddModelError("", "验证码不正确");
                    return(View(model));
                }

                if (string.IsNullOrEmpty(model.Refer.Trim()))
                {
                    ModelState.AddModelError("", "邀请码不正确");
                    return(View(model));
                }
                PaginationInfo paging = new PaginationInfo();
                IList <User>   users  = iuser.Get(null, model.Refer.Trim(), null, null, null, null, null, null, null, null, 1, 0, null, out paging);
                if (users == null || users.Count == 0)
                {
                    ModelState.AddModelError("", "邀请码不正确");
                    return(View(model));
                }

                User newuser = AutoMapper.Mapper.Map <User>(model);
                newuser.Role    = 2;
                newuser.Statues = 1;
                newuser.IsSuper = false;
                newuser.Liked   = 0;
                newuser.Ip      = null;
                //newuser.IsLogin = true;
                newuser.ID            = Guid.NewGuid();
                newuser.Lastlogintime = DateTime.Now;
                newuser.Point         = 0;
                newuser.Refer         = model.Refer;
                newuser.Balance       = 0;

                Guid userid = iuser.Create(newuser);
                if (userid == newuser.ID)
                {
                    ICustomPrincipal cp = new CustomPrincipal();
                    cp.Login(model.UserName, userid.ToString(), true);
                    WriteLog(model.UserName + " 注册网站");
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "注册失败");
                    return(View(model));
                }
                //WebSecurity.CreateUserAndAccount(model.UserName, model.Password);
            }

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