Example #1
0
        public ActionResult Login(MemberInfo model,FormCollection fc){
            bool errors = false;
            
            if (string.IsNullOrEmpty(model.UserName))
            {
                errors = true;
                ModelState.AddModelError("UserName", "The user name can not be empty");
            }
            if (string.IsNullOrEmpty(model.UserPassword))
            {
                errors = true;
                ModelState.AddModelError("UserPassword", "Passwords can not be empty");
            }
            if(!errors && ModelState.IsValid){
                var userInfo = MemberService.Get(model.UserName);
                if (userInfo.UserPassword == model.UserPassword)
                {

                    ElcoHttpContext.Current.LoginEvent(ElcoHttpContext.Current.CookieName, userInfo);

                    return Redirect("/download");
                }
                else {
                    ViewBag.Status = "NotLogined";
                }
            }            
            return View();
        }
Example #2
0
 /// <summary>
 /// 插入或编辑
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static MemberInfo Create(MemberInfo model) {
     if (model.Id == 0)
     {
         int id = MemberManage.Insert(model);
         model.Id = id;
     }
     else {
         MemberManage.Update(model);
     }
         return model;
 }/// <summary>
Example #3
0
 /// <summary>
 /// 插入用户
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static int Insert(MemberInfo model) {
     string strSQL = "INSERT INTO Members(UserName,UserPassword,CreateDateTime,RealName,Position,Company,Email,Phone) VALUES(@UserName,@Userpassword,GETDATE(),@RealName,@Position,@Company,@Email,@Phone);SELECT @@IDENTITY;";
     SqlParameter[] param = { 
                             new SqlParameter("UserName",SqlDbType.NVarChar),
                             new SqlParameter("UserPassword",SqlDbType.NVarChar),
                             new SqlParameter("RealName",SqlDbType.NVarChar),
                             new SqlParameter("Position",SqlDbType.NVarChar),
                             new SqlParameter("Company",SqlDbType.NVarChar),
                             new SqlParameter("Email",SqlDbType.NVarChar),
                             new SqlParameter("Phone",SqlDbType.NVarChar),
                            };
     param[0].Value = model.UserName ?? string.Empty;
     param[1].Value = model.UserPassword ?? string.Empty;
     param[2].Value = model.RealName ?? string.Empty;
     param[3].Value = model.Position ?? string.Empty;
     param[4].Value = model.Company ?? string.Empty;
     param[5].Value = model.Email ?? string.Empty;
     param[6].Value = model.Phone ?? string.Empty;
     return Convert.ToInt32(SQLPlus.ExecuteScalar(CommandType.Text,strSQL,param));
 }
Example #4
0
        public ActionResult Login(MemberInfo model) {

            bool errors = false;
            if(string.IsNullOrEmpty(model.UserName)){
                ModelState.AddModelError("UserNameEmpty", "Please enter your user name.");
                errors = true;
            }
            if(string.IsNullOrEmpty(model.UserPassword)){
                errors = true;
                ModelState.AddModelError("UserPasswordEmpty", "Please enter a password.");
            }
            if (!errors && ModelState.IsValid)
            {
                if(MemberService.ValidateAdmin(model.UserName,model.UserPassword)){
                    var memberInfo = MemberService.Get(model.UserName);
                    ElcoHttpContext.Current.LoginEvent(ElcoHttpContext.Current.AdminCookieName,memberInfo);
                    return Redirect("/pagesadmin/");
                }
                ModelState.AddModelError("LoginError", "User name or password is incorrect, please try again.");               
                
            }
            return View();
        }
Example #5
0
        public ActionResult Login(MemberInfo model) {

            bool errors = false;
            if(string.IsNullOrEmpty(model.UserName)){
                ModelState.AddModelError("UserNameEmpty","请输入用户名!");
                errors = true;
            }
            if(string.IsNullOrEmpty(model.UserPassword)){
                errors = true;
                ModelState.AddModelError("UserPasswordEmpty","请输入密码!");
            }
            if (!errors && ModelState.IsValid)
            {
                if(MemberService.ValidateAdmin(model.UserName,model.UserPassword)){
                    var memberInfo = MemberService.Get(model.UserName);
                    ElcoHttpContext.Current.LoginEvent(ElcoHttpContext.Current.AdminCookieName,memberInfo);
                    return Redirect("/pagesadmin/");
                }
                ModelState.AddModelError("LoginError","用户名或密码错误,请重试!");               
                
            }
            return View();
        }
Example #6
0
        public ActionResult Register(MemberInfo model) {

            bool errors = false;

            if(string.IsNullOrEmpty(model.UserName)){
                errors = true;
                ModelState.AddModelError("UserName", "The user name can not be empty");
            }
            if(string.IsNullOrEmpty(model.UserPassword)){
                errors = true;
                ModelState.AddModelError("UserPassword", "Passwords can not be empty");
            }
            if(!errors && ModelState.IsValid){
                //验证用户名是否存在
                errors = MemberService.Get(model.UserName).Id>0;
                if (!errors)
                {
                    //验证Email是否存在
                    if (MemberService.EmailExists(model.Email))
                    {
                        ModelState.AddModelError("EmailExists", "Email already exists");
                    }
                    else
                    {
                        MemberService.Create(model);
                        //显示注册成功页面
                        return View("RegisterSuccess", model);
                    }
                }
                else {
                    ViewBag.Status = "UserNameExists";
                }
            }

            return View(model);
        }
Example #7
0
 /// <summary>
 /// 更新用户,暂时没有功能
 /// </summary>
 /// <param name="model"></param>
 /// <returns></returns>
 public static int Update(MemberInfo model) {
     //string strSQL = "";
     //return SQLPlus
     return 0;
 }
Example #8
0
        /// <summary>
        /// 写Cookie信息,后台和前台通用
        /// </summary>
        /// <param name="cookieName"></param>
        /// <param name="userInfo"></param>
        public void LoginEvent(string cookieName, MemberInfo userInfo)
        {
            //登陆
            //正确,开始写Cookie                            
            //Cookie格式Id|UserName|Password|DateTime.Now
            string cookieValue = string.Format("{0}|{1}|{2}|{3}",
                userInfo.Id,
                userInfo.UserName,
                userInfo.UserPassword,
                DateTime.Now);

            //添加到浏览器中
            //Cookie加密
            string cv = Goodspeed.Library.Security.DESCryptography.Encrypt(cookieValue, DESKey);
            System.Web.HttpContext.Current.Response.Cookies.Add(new HttpCookie(cookieName, cv) { Expires = DateTime.Now.AddMinutes(this.CookieExpires), Domain = CookieDomain });
        }
Example #9
0
        public ActionResult MiniLogin(MemberInfo model,FormCollection fc) {
            bool errors = false;

            if (string.IsNullOrEmpty(model.UserName))
            {
                errors = true;
                ModelState.AddModelError("UserName", "用户名不能为空");
            }
            if (string.IsNullOrEmpty(model.UserPassword))
            {
                errors = true;
                ModelState.AddModelError("UserPassword", "密码不能为空");
            }
            if (!errors && ModelState.IsValid)
            {
                var userInfo = MemberService.Get(model.UserName);
                if (userInfo.UserPassword == model.UserPassword)
                {
                    ElcoHttpContext.Current.LoginEvent(ElcoHttpContext.Current.CookieName,userInfo);

                    ViewBag.Status = "OK";
                }
                else
                {
                    ViewBag.Status = "NotLogined";
                }
            }
            return View();
        }