public static void LogonUser(string userCode, string password, LogonSuccessDelegate <User> onSuccess, LogonFailureDelegate onFailure, string connectstring_Or_Dbname) { IList <User> users = BuilderFactory.DefaultBulder(connectstring_Or_Dbname).List <User>(new User { UserCode = TypeConverter.ChangeString(userCode) }); if (users.Count > 0) { string passHash = password ?? ""; if (passHash.Length != 32) { passHash = MD5Provider.Generate(password); } var query = users.Where(item => TypeConverter.ChangeString(item.PasswordHash) == passHash); if (query.Count() > 0) { User user = query.First(); if (user.StopFlag == 1) { if (onFailure != null) { onFailure(new LogonFailureEventArgs("此帐号已停用,请联系管理员")); } } else { if (onSuccess != null) { onSuccess(new LogonSuccessEventArgs <User>(user, HttpContext.Current.Request.UserHostAddress)); } } } else { if (onFailure != null) { onFailure(new LogonFailureEventArgs("您输入的密码有误,请重新输入")); } } } else { if (onFailure != null) { onFailure(new LogonFailureEventArgs(string.Format("此帐号【{0}】不存在", userCode))); } } }
public static void LogonUserByToken(string applicationIdFrom, string applicationIdTo, string token, LogonSuccessDelegate <User> onSuccess, LogonFailureDelegate onFailure, string connectstring_Or_Dbname) { ObjectToken theOne = BuilderFactory.DefaultBulder(GlobalManager.getConnectString()).Load <ObjectToken, ObjectTokenPK>(new ObjectTokenPK { Token = token.ToGuid() }); if (theOne.Token != null && theOne.ApplicationIdFrom == applicationIdFrom && theOne.ApplicationIdTo == applicationIdTo) { if (theOne.ObjectType == "00001") { //用户 if ((theOne.ExpireOn.Value - DateTime.Now).TotalSeconds > 0) { User user = BuilderFactory.DefaultBulder(connectstring_Or_Dbname).Load <User, UserPK>(new UserPK { UserId = theOne.ObjectId.ToGuid() }); if (user.UserId != null) { if (user.StopFlag == 1) { if (onFailure != null) { onFailure(new LogonFailureEventArgs("此帐号已停用,请联系管理员")); } } else { if (onSuccess != null) { onSuccess(new LogonSuccessEventArgs <User>(user, HttpContext.Current.Request.UserHostAddress)); } } } else { if (onFailure != null) { onFailure(new LogonFailureEventArgs("用户不存在")); } } } else { if (onFailure != null) { onFailure(new LogonFailureEventArgs(string.Format("token【{0}】已过期", token))); } } } else { if (onFailure != null) { onFailure(new LogonFailureEventArgs(string.Format("非法的token【{0}】", token))); } } } else { if (onFailure != null) { onFailure(new LogonFailureEventArgs(string.Format("无效的token【{0}】", token))); } } }
public static void LogonUser(string userCode, string password, LogonSuccessDelegate <User> onSuccess, LogonFailureDelegate onFailure) { LogonUser(userCode, password, onSuccess, onFailure, null); }
public static void LogonUserByToken(string applicationIdFrom, string applicationIdTo, string token, LogonSuccessDelegate <User> onSuccess, LogonFailureDelegate onFailure) { LogonUserByToken(applicationIdFrom, applicationIdTo, token, onSuccess, onFailure, null); }