public string NewToken(token tokenModel) { tokenModel.Token = Guid.NewGuid().ToString("N"); tokenModel.CreatedDate = DateTime.Now; tokenModel.ExpiredDate = DateTime.Now.AddYears(1); using (var dbContext = new DataEntities()) { dbContext.Tokens.AddObject(tokenModel); dbContext.SaveChanges(); } return tokenModel.Token; }
/// <summary> /// 创建新的 token 对象。 /// </summary> /// <param name="token1">Token 属性的初始值。</param> public static token Createtoken(global::System.String token1) { token token = new token(); token.Token = token1; return token; }
/// <summary> /// 用于向 Tokens EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet<T> 属性的 .Add 方法。 /// </summary> public void AddToTokens(token token) { base.AddObject("Tokens", token); }
public bool Login(string userName, string password,out UserModel user, bool isAdminLoginFromPortal = false,string clientIP = null,string macAddr = null) { user = null; bool isLogin = false; string md5Password = isAdminLoginFromPortal ? MD5Helper.GetMd5Hash(password) : password; UserRepository ur = new UserRepository(); User dbuser = ur.Login(userName, md5Password); if (dbuser != null) { user = ConvertDBUserToBizUser(dbuser); // 客户端用户不能登录后台管理系统 if (isAdminLoginFromPortal && (int)RoleType.ClientUsers == user.UserType) { isLogin = false; } else { isLogin = true; TokenRepository tr = new TokenRepository(); var tokenModel = new token { IP = clientIP, MacAddr = macAddr, UserName = userName }; user.Token = tr.NewToken(tokenModel); // login success, add login record LoginRecordRepository recordRep = new LoginRecordRepository(); LoginRecord loginRecord = new LoginRecord { IsLoginFromClient = isAdminLoginFromPortal ? 0 : 1, LoginIP = clientIP, UserName = userName }; recordRep.Add(loginRecord); } } return isLogin; }