Example #1
0
        // GET: Admin/Home
        public async Task <ActionResult> Index()
        {
            var loginname = Session["loginAdmin"].ToString();

            IBLL.IUserManager userManager = new BLL.UserManager();
            var usermodel = await userManager.GetUserByEmail(loginname);

            return(View(usermodel));
        }
Example #2
0
        public async Task <ActionResult> Login(AdminLoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                IBLL.IUserManager userManager = new BLL.UserManager();
                Guid userId;
                if (userManager.Login(model.Email, model.LoginPwd, out userId))
                {
                    var usermodel = await userManager.GetUserByEmail(model.Email);

                    if (usermodel.Type == 0)
                    {
                        ModelState.AddModelError("", "该账号没有管理权限");
                        return(View(model));
                    }
                    //跳转
                    //用session还是用cookie
                    if (model.RememberMe)
                    {
                        Response.Cookies.Add(new HttpCookie("loginAdmin")
                        {
                            Value   = model.Email,
                            Expires = DateTime.Now.AddDays(7)
                        });
                        Response.Cookies.Add(new HttpCookie("adminId")
                        {
                            Value   = userId.ToString(),
                            Expires = DateTime.Now.AddDays(7)
                        });
                    }
                    else
                    {
                        Session["loginAdmin"] = model.Email;
                        Session["adminId"]    = userId;
                    }
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "用户名密码错误");
                }
            }
            else
            {
                ModelState.AddModelError("", "您的账号密码有误");
            }
            return(View(model));
        }
Example #3
0
        public async Task <IHttpActionResult> Register(LoginViewModel model)
        {
            if (ModelState.IsValid)
            {
                IBLL.IUserManager userManager = new BLL.UserManager();
                if (await userManager.GetUserByEmail(model.Email) == null)
                {
                    await userManager.Register(model.Email, model.LoginPwd);

                    return(this.SendData("注册成功"));
                }
                return(this.ErrorData("邮箱已注册"));
            }

            return(this.ErrorData("输入数据不合法"));
        }
Example #4
0
        public async Task <ActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                IBLL.IUserManager userManager = new BLL.UserManager();
                if (await userManager.GetUserByEmail(model.Email) == null)
                {
                    await userManager.Register(model.Email, model.Password);

                    return(RedirectToAction("Index", "Home"));
                }

                ModelState.AddModelError("", "邮箱已存在");
            }

            return(View(model));
        }