//TODO:移到存储过程里 /// <summary> /// 完成注册及用户初始化相关操作 /// </summary> /// <param name="name"></param> /// <param name="pwd"></param> /// <param name="email"></param> /// <param name="code"></param> /// <param name="srcid"></param> /// <returns></returns> public static bool Signup(string name, string pwd, string email, string code, string sid) { string www = UserAccount.GetWWW(name); //normal signup int id = -1; if (string.IsNullOrEmpty(code)) { id = UserAccount.Create(name, pwd, email, www); if (id > 0) { UserData.Initialize(name, www, id, sid, null); } } else { if (UserData.LockCode(code, sid)) //invited signup { id = UserAccount.Create(name, pwd, email, www); if (id > 0) { UserData.Initialize(name, www, id, sid, code); } else { UserData.UnLockCode(code); } } } if (id > 0) { //create feed of signup event EventFeed.CreateEvent(0, 5, id, -1, "signup", ""); //添加默认好友 //write cookie string nid = id.ToString(); QA.SetCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(new FormsAuthenticationTicket(1, nid, DateTime.Now, DateTime.Now.AddDays(1.0), true, nid, FormsAuthentication.FormsCookiePath)) , DateTime.MaxValue); //设置永久保留登录信息,之后版本可考虑进行配置 QA.SetCookie(SC.CN.A_NAME, HttpUtility.UrlEncode(name), DateTime.MaxValue); string cookie = QA.GetCookie(SC.CN.FROM); return(true); } return(false); }
/// <summary> /// 用户登录 /// </summary> /// <param name="name"></param> /// <param name="pwd"></param> /// <returns></returns> public static bool Login(string name, string pwd) { UserEntity entity = null; pwd = MU.MD5(pwd); try { if (name.Contains("@")) { entity = UserData.LoginByEmail(name, pwd); } else { entity = UserData.LoginByName(name, pwd); } //write cookie if (entity != null) { CacheService.Add(CNC.ACCOUNT_ENTITY_ID + entity.id, entity); string id = entity.id.ToString(); // id 仅作内部使用,不对外公开 QA.SetCookie(FormsAuthentication.FormsCookieName, FormsAuthentication.Encrypt(new FormsAuthenticationTicket(1, id, DateTime.Now, DateTime.MaxValue, true, id, FormsAuthentication.FormsCookiePath)) , DateTime.MaxValue); //设置永久保留登录信息,之后版本可考虑进行配置 QA.SetCookie(SC.CN.A_NAME, HttpUtility.UrlEncode(entity.name), DateTime.MaxValue); string cookie = QA.GetCookie(SC.CN.FROM); //TODO: write log,add to task. Log.Login(entity); } } catch { } return(entity != null); }