Exemple #1
0
        public static bool Register(UserProfile userInfo, out string errorMsg)
        {
            errorMsg = "";
            UserProfile regInfo = new UserProfile()
            {
                UserName = userInfo.UserName,
                Password = SecurityHelper.Encrypt(userInfo.Password),
                RoleId=1//权限角色
            };
            int registerState;
            UserProfileData userPorfile=new UserProfileData();
            var userList=userPorfile.select(0," username ","username='******'",null);
            bool  isNewName = true ;
            if (userList.Count > 0)
            {
                isNewName = false;
                errorMsg = "该用户名已注册";
                return isNewName;

            }
            try
            {
                registerState = userPorfile.insert(regInfo);
                if (registerState > 0)
                {
                    return true;
                }
                else return false;
            }
            catch (Exception ex)
            {
                errorMsg = "注册出错" + ex.ToString();
                return false;
            }
        }
 public int insert(UserProfile users)
 {
     return insert( users.UserName, users.Password, users.RoleId);
 }
        public ActionResult Register(UserProfile userInfo)
        {
            string errorMsg = "";

            bool success = UserHelper.Register(userInfo, out errorMsg);

            return Json(new { success = success, msg = errorMsg },
                JsonRequestBehavior.AllowGet);
        }
 public static int update(UserProfile users)
 {
     return update(users.UserId, users.UserName, users.Password, users.RoleId);
 }
Exemple #5
0
        /// <summary>
        /// 将用户信息写入缓存以及Cookies
        /// </summary>
        /// <param name="onlineUser">当前用户信息</param>
        private static void SetCurrentUserInfo(UserProfile onlineUser)
        {
            HttpContext.Current.Session[CURRENT_USER_INFO] = onlineUser;
            HttpContext.Current.Session.Timeout = AUTH_TIMEOUT; // 注意此处是设置所有session的过期时间

            DateTime expiration = DateTime.Now;
            FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
                1,
                onlineUser.UserName,
                expiration,
                expiration.AddMinutes(AUTH_TIMEOUT),
                true,
                onlineUser.UserId.ToString());

            HttpContext.Current.Response.Cookies[FormsAuthentication.FormsCookieName].Value = FormsAuthentication.Encrypt(ticket);
            HttpContext.Current.Response.Cookies[FormsAuthentication.FormsCookieName].Expires = ticket.Expiration;
            HttpContext.Current.Response.Cookies[FormsAuthentication.FormsCookieName].HttpOnly = true;
        }