예제 #1
0
        public ActionResult VerifyPassword(FormCollection collection)
        {
            if (!String.IsNullOrWhiteSpace(collection["Email"]) && !String.IsNullOrWhiteSpace(collection["NewPwd"]))
            {
                string secretKey = collection["SecretKey"];
                string username  = collection["Email"].Trim();
                string password  = collection["NewPwd"];

                YSWL.MALL.BLL.SysManage.VerifyMail bll = new YSWL.MALL.BLL.SysManage.VerifyMail();

                YSWL.MALL.Model.SysManage.VerifyMail model = bll.GetModel(secretKey);
                if (model == null || !model.ValidityType.HasValue || model.ValidityType.Value != 1 ||
                    model.UserName != username)
                {
                    //非法修改密码
                    LogHelp.AddInvadeLog("Areas.SNS.Controllers-HttpPost-VerifyPassword", System.Web.HttpContext.Current.Request);
                    return(HttpNotFound());
                }

                User currentUser = new User(username);
                if (String.IsNullOrWhiteSpace(password))
                {
                    ModelState.AddModelError("Error", "该用户不存在!");
                    return(View());
                }
                currentUser.Password = AccountsPrincipal.EncryptPassword(YSWL.Common.PageValidate.InputText(password, 30));
                if (!currentUser.Update())
                {
                    ModelState.AddModelError("Error", "密码重置失败,请检查输入的信息是否正确或者联系管理员!");
                    return(View());
                }
                else
                {
                    AccountsPrincipal newUser = AccountsPrincipal.ValidateLogin(username, password);
                    FormsAuthentication.SetAuthCookie(username, false);
                    Session[Globals.SESSIONKEY_USER] = currentUser;
                    Session["Style"] = currentUser.Style;
                    YSWL.MALL.BLL.Members.PointsDetail pointBll = new BLL.Members.PointsDetail();
                    pointBll.AddPoints(1, currentUser.UserID, "登录操作");
                    BLL.Members.RankDetail.AddScore(1, currentUser.UserID, "登录操作");
                    if (Session["returnPage"] != null)
                    {
                        string returnpage = Session["returnPage"].ToString();
                        Session["returnPage"] = null;
                        return(Redirect(returnpage));
                    }
                    else
                    {
                        return(RedirectToAction("Posts", "Profile"));
                    }
                }
            }
            return(View());
        }
예제 #2
0
        public ActionResult AjaxLogin(string UserName, string UserPwd)
        {
            bool IsCloseLogin = YSWL.MALL.BLL.SysManage.ConfigSystem.GetBoolValueByCache("System_Close_Login");

            if (IsCloseLogin)
            {
                return(Content("-1"));
            }
            if (ModelState.IsValid)
            {
                AccountsPrincipal userPrincipal = AccountsPrincipal.ValidateLogin(UserName, UserPwd);
                if (userPrincipal != null)
                {
                    User currentUser = new YSWL.Accounts.Bus.User(userPrincipal);
                    if (!currentUser.Activity)
                    {
                        ModelState.AddModelError("Message", "对不起,该帐号已被冻结,请联系管理员!");
                    }
                    //if (currentUser.UserType == "AA")
                    //{
                    //    ModelState.AddModelError("Message", "您是管理员用户,您没有权限登录后台系统!") ;
                    //}
                    HttpContext.User = userPrincipal;
                    FormsAuthentication.SetAuthCookie(UserName, true);
                    Session[YSWL.Common.Globals.SESSIONKEY_USER] = currentUser;
                    //登录成功加积分
                    YSWL.MALL.BLL.Members.PointsDetail pointBll = new BLL.Members.PointsDetail();
                    int pointers  = pointBll.AddPoints(1, currentUser.UserID, "登录操作");
                    int rankScore = BLL.Members.RankDetail.AddScore(1, currentUser.UserID, "登录操作");
                    return(Content(string.Format("1|{0}|{1}", pointers, rankScore)));
                }
                else
                {
                    return(Content("0"));
                }
            }
            return(Content("0"));
        }
예제 #3
0
        public ActionResult Login(MALL.ViewModel.SNS.LogOnModel model, string returnUrl)
        {
            ViewBag.Title = "登录";
            bool IsCloseLogin = YSWL.MALL.BLL.SysManage.ConfigSystem.GetBoolValueByCache("System_Close_Login");

            if (IsCloseLogin)
            {
                return(RedirectToAction("TurnOff", "Error"));
            }
            if (ModelState.IsValid)
            {
                AccountsPrincipal userPrincipal = AccountsPrincipal.ValidateLogin(model.Email, model.Password);
                if (userPrincipal == null)
                {
                    ModelState.AddModelError("Message", "用户名或密码不正确, 请重新输入!");
                    return(View(model));
                }

                User currentUser = new YSWL.Accounts.Bus.User(userPrincipal);
                if (!currentUser.Activity)
                {
                    ModelState.AddModelError("Message", "对不起,该帐号已被冻结,请联系管理员!");
                    return(View(model));
                }
                HttpContext.User = userPrincipal;
                FormsAuthentication.SetAuthCookie(model.Email, model.RememberMe);
                Session[YSWL.Common.Globals.SESSIONKEY_USER] = currentUser;
                //登录成功加积分
                YSWL.MALL.BLL.Members.PointsDetail pointBll = new BLL.Members.PointsDetail();
                int pointers  = pointBll.AddPoints(1, currentUser.UserID, "登录操作");
                int rankScore = BLL.Members.RankDetail.AddScore(1, currentUser.UserID, "登录操作");

                #region 默认加小组  加失败之后显示加入小组按钮
                //加入小组
                YSWL.MALL.Model.SNS.GroupUsers groupModel = new Model.SNS.GroupUsers();
                if (!bll.Exists(GroupId, currentUser.UserID))
                {
                    groupModel.GroupID  = GroupId;
                    groupModel.JoinTime = DateTime.Now;
                    groupModel.NickName = currentUser.NickName;
                    groupModel.UserID   = currentUser.UserID;
                    groupModel.Status   = 1;
                    if (!bll.AddEx(groupModel))
                    {
                        ViewBag.joined = "error";
                    }
                }
                #endregion


                //加载Shop模块的购物车
                if (CurrentThemeName == "TaoLe")
                {
                    BLL.Shop.Products.ShoppingCartHelper.LoadShoppingCart(currentUser.UserID);
                }

                if (Session["ReturnUrl"] != null && !String.IsNullOrWhiteSpace(Session["ReturnUrl"].ToString()))
                {
                    returnUrl = Session["ReturnUrl"].ToString();
                    Session.Remove("ReturnUrl");
                    return(Redirect(returnUrl));
                }
                if (Url.IsLocalUrl(returnUrl) && returnUrl.Length > 1 && returnUrl.StartsWith("/") &&
                    !returnUrl.StartsWith("//") && !returnUrl.StartsWith("/\\"))
                {
                    return(Redirect(returnUrl));
                }
                else
                {
                    TempData["pointer"]   = pointers;
                    TempData["rankScore"] = rankScore;
                    return(RedirectToAction("Index", "Home"));
                }
            }
            return(View(model));
        }
예제 #4
0
        public ActionResult Register(MALL.ViewModel.SNS.RegisterModel model)
        {
            ViewBag.Title = "注册";
            bool IsCloseLogin = YSWL.MALL.BLL.SysManage.ConfigSystem.GetBoolValueByCache("System_Close_Register");

            if (IsCloseLogin)
            {
                return(RedirectToAction("TurnOff", "Error"));
            }
            if (ModelState.IsValid)
            {
                //判断昵称是否已存在
                //判断邮箱是否已存在

                User newUser = new User();
                //DONE: 警告DB字段未对应: Email 字段 varchar(100) UserName 字段 varchar(50) 已完成 BEN DONE 2012-11-22
                newUser.UserName        = model.Email;
                newUser.NickName        = model.NickName; //昵称名称相同
                newUser.Password        = AccountsPrincipal.EncryptPassword(model.Password);
                newUser.Email           = model.Email;
                newUser.Activity        = true;
                newUser.UserType        = "UU";
                newUser.Style           = 1;
                newUser.User_dateCreate = DateTime.Now;
                newUser.User_cLang      = "zh-CN";
                int userid = newUser.Create();
                if (userid == -100)
                {
                    ModelState.AddModelError("Message", ErrorCodeToString(MembershipCreateStatus.DuplicateUserName));
                }
                else
                {
                    //添加用户扩展表数据
                    BLL.Members.UsersExp ue = new BLL.Members.UsersExp();
                    ue.UserID                     = userid;
                    ue.BirthdayVisible            = 0;
                    ue.BirthdayIndexVisible       = false;
                    ue.Gravatar                   = string.Format("/{0}/User/Gravatar/{1}", MvcApplication.UploadFolder, userid);
                    ue.ConstellationVisible       = 0;
                    ue.ConstellationIndexVisible  = false;
                    ue.NativePlaceVisible         = 0;
                    ue.NativePlaceIndexVisible    = false;
                    ue.RegionId                   = 0;
                    ue.AddressVisible             = 0;
                    ue.AddressIndexVisible        = false;
                    ue.BodilyFormVisible          = 0;
                    ue.BodilyFormIndexVisible     = false;
                    ue.BloodTypeVisible           = 0;
                    ue.BloodTypeIndexVisible      = false;
                    ue.MarriagedVisible           = 0;
                    ue.MarriagedIndexVisible      = false;
                    ue.PersonalStatusVisible      = 0;
                    ue.PersonalStatusIndexVisible = false;
                    ue.LastAccessIP               = "";
                    ue.LastAccessTime             = DateTime.Now;
                    ue.LastLoginTime              = DateTime.Now;
                    ue.LastPostTime               = DateTime.Now;
                    if (!ue.Add(ue))
                    {
                        userManage.Delete(userid);
                        userExpManage.Delete(userid);
                        ModelState.AddModelError("Message", "注册失败!");
                        return(View(model));
                    }
                    FormsAuthentication.SetAuthCookie(model.Email, false /* createPersistentCookie */);
                    #region
                    //注册加积分
                    YSWL.MALL.BLL.Members.PointsDetail pointBll = new BLL.Members.PointsDetail();
                    pointBll.AddPoints(2, userid, "注册成功");
                    BLL.Members.RankDetail.AddScore(2, userid, "注册成功");
                    YSWL.MALL.Model.SNS.UserAlbums AlbumsModel = new Model.SNS.UserAlbums();
                    YSWL.MALL.BLL.SNS.UserAlbums   AlbumsBll   = new YSWL.MALL.BLL.SNS.UserAlbums();
                    YSWL.MALL.BLL.SNS.UserShip     ShipBll     = new YSWL.MALL.BLL.SNS.UserShip();
                    AlbumsModel.AlbumName       = "默认专辑";
                    AlbumsModel.CreatedDate     = DateTime.Now;
                    AlbumsModel.CreatedNickName = model.NickName;
                    AlbumsModel.CreatedUserID   = userid;
                    AlbumsBll.AddEx(AlbumsModel, 1);

                    string DefaultGravatar = BLL.SysManage.ConfigSystem.GetValueByCache("DefaultGravatar");
                    DefaultGravatar = string.IsNullOrEmpty(DefaultGravatar) ? "/Upload/User/Gravatar/Default.jpg" : DefaultGravatar;
                    string TargetGravatarFile = BLL.SysManage.ConfigSystem.GetValueByCache("TargetGravatarFile");
                    TargetGravatarFile = string.IsNullOrEmpty(TargetGravatarFile) ? "/Upload/User/Gravatar/" : TargetGravatarFile;
                    string path = ControllerContext.HttpContext.Server.MapPath("/");
                    if (System.IO.File.Exists(path + DefaultGravatar))
                    {
                        System.IO.File.Copy(path + DefaultGravatar, path + TargetGravatarFile + userid + ".jpg", true);
                    }
                    //自动给是粉丝
                    ShipBll.GiveUserFellow(userid);
                    #endregion
                    ////return Content("<script >alert('注册成功!');</script >", "text/html");   //通用后,放到基类里
                    //string script = String.Format("<script defer>alert('注册成功!');location.href='{0}'</script>", Url.Action("Login"));
                    //return Content(script, "text/html");

                    return(Redirect("/MSNS/Home/Index"));
                }
            }

            return(View(model));
        }