public ResponseBase SetClientMinerProfileProperty(SetClientMinerProfilePropertyRequest request) { if (request == null) { return(LoadClientResponse.InvalidInput(Guid.Empty, "参数错误")); } try { if (string.IsNullOrEmpty(request.LoginName)) { return(ResponseBase.InvalidInput(request.MessageId, "登录名不能为空")); } if (!HostRoot.Current.UserSet.TryGetKey(request.LoginName, out IUser key)) { return(ResponseBase.Forbidden(request.MessageId)); } if (!request.Timestamp.IsInTime()) { return(ResponseBase.Expired(request.MessageId)); } throw new NotImplementedException(); } catch (Exception e) { Global.Logger.ErrorDebugLine(e.Message, e); return(ResponseBase.ServerError(request.MessageId, e.Message)); } }
public ResponseBase RemoveNTMinerFile(RemoveNTMinerFileRequest request) { if (request == null) { return(LoadClientResponse.InvalidInput(Guid.Empty, "参数错误")); } try { if (string.IsNullOrEmpty(request.LoginName)) { return(ResponseBase.InvalidInput(request.MessageId, "登录名不能为空")); } if (!HostRoot.Current.UserSet.TryGetKey(request.LoginName, out IUser key)) { return(ResponseBase.Forbidden(request.MessageId)); } if (!request.Timestamp.IsInTime()) { return(ResponseBase.Expired(request.MessageId)); } if (request.GetSign(key.Password) != request.Sign) { return(ResponseBase.Forbidden(request.MessageId, "签名验证未通过")); } HostRoot.Current.NTMinerFileSet.Remove(request.NTMinerId); return(ResponseBase.Ok(request.MessageId)); } catch (Exception e) { Global.Logger.Error(e.Message, e); return(ResponseBase.ServerError(request.MessageId, e.Message)); } }
public ResponseBase SetCoinKernelProfileProperty(SetCoinKernelProfilePropertyRequest request) { if (request == null) { return(LoadClientResponse.InvalidInput(Guid.Empty, "参数错误")); } try { if (string.IsNullOrEmpty(request.LoginName)) { return(ResponseBase.InvalidInput(request.MessageId, "登录名不能为空")); } if (!HostRoot.Current.UserSet.TryGetKey(request.LoginName, out IUser key)) { return(ResponseBase.Forbidden(request.MessageId)); } if (!request.Timestamp.IsInTime()) { return(ResponseBase.Expired(request.MessageId)); } if (!HostRoot.Current.MineWorkSet.Contains(request.WorkId)) { return(ResponseBase.InvalidInput(request.MessageId, "给定的workId不存在")); } if (request.Sign != request.GetSign(key.Password)) { return(ResponseBase.Forbidden(request.MessageId, "签名验证未通过")); } HostRoot.Current.MineProfileManager.SetCoinKernelProfileProperty(request.WorkId, request.CoinKernelId, request.PropertyName, request.Value); return(ResponseBase.Ok(request.MessageId)); } catch (Exception e) { Global.Logger.ErrorDebugLine(e.Message, e); return(ResponseBase.ServerError(request.MessageId, e.Message)); } }
public ResponseBase LoginControlCenter(LoginControlCenterRequest request) { if (request == null) { return(LoadClientsResponse.InvalidInput(Guid.Empty, "参数错误")); } try { if (string.IsNullOrEmpty(request.LoginName)) { return(ResponseBase.Forbidden(request.MessageId, "登录名不能为空")); } if (!HostRoot.Current.UserSet.TryGetKey(request.LoginName, out IUser key)) { return(ResponseBase.Forbidden(request.MessageId, "登录名不存在")); } if (!request.Timestamp.IsInTime()) { return(ResponseBase.Expired(request.MessageId)); } if (request.Sign != request.GetSign(key.Password)) { return(ResponseBase.Forbidden(request.MessageId, "密码错误")); } return(ResponseBase.Ok(request.MessageId)); } catch (Exception e) { Global.Logger.ErrorDebugLine(e.Message, e); return(ResponseBase.ServerError(request.MessageId, e.Message)); } }
protected bool IsValidAdmin <TResponse>(ISignableData data, out TResponse response, out UserData user) where TResponse : ResponseBase, new() { user = null; if (!WebApiRoot.UserSet.IsReadied) { string message = "服务器用户集启动中,请稍后"; response = ResponseBase.NotExist <TResponse>(message); return(false); } ClientSignData query = ClientSign; if (!Timestamp.IsInTime(query.Timestamp)) { response = ResponseBase.Expired <TResponse>(); return(false); } if (!string.IsNullOrEmpty(query.LoginName)) { user = WebApiRoot.UserSet.GetUser(query.UserId); } if (user == null && !string.IsNullOrEmpty(query.LoginName)) { user = WebApiRoot.UserSet.GetUser(query.UserId); } if (user == null) { string message = "用户不存在"; response = ResponseBase.NotExist <TResponse>(message); return(false); } else if (!user.IsAdmin()) { string message = "对不起,您不是超管"; response = ResponseBase.NotExist <TResponse>(message); return(false); } string mySign = RpcUser.CalcSign(user.LoginName, user.Password, query.Timestamp, data); if (query.Sign != mySign) { string message = "登录名或密码错误"; response = ResponseBase.Forbidden <TResponse>(message); Write.DevDebug(() => $"{message} sign:{query.Sign} mySign:{mySign}"); return(false); } response = null; return(true); }
private static bool IsValidUser( ClientSignData clientSign, ISignableData data, bool isLoginAction, out ResponseBase response, out UserData user) { user = null; if (!AppRoot.UserSet.IsReadied) { string message = "服务器用户集启动中,请稍后"; response = ResponseBase.NotExist(message); return(false); } if (!Timestamp.IsInTime(clientSign.Timestamp)) { response = ResponseBase.Expired(); return(false); } if (!string.IsNullOrEmpty(clientSign.LoginName)) { user = AppRoot.UserSet.GetUser(clientSign.UserId); } if (user == null) { string message = "用户不存在"; response = ResponseBase.NotExist(message); return(false); } if (isLoginAction) { if (!AppRoot.UserSet.CheckLoginTimes(clientSign.LoginName)) { response = ResponseBase.Forbidden("对不起,您的尝试太过频繁"); return(false); } } string mySign = HashUtil.CalcSign(user.LoginName, user.Password, clientSign.Timestamp, data); if (clientSign.Sign != mySign) { string message = "签名错误:1. 可能因为登录名或密码错误;2. 可能因为软件版本过期需要升级软件。"; response = ResponseBase.Forbidden(message); return(false); } response = null; return(true); }
protected bool IsValidUser <TResponse>(ISignableData data, out TResponse response, out UserData user) where TResponse : ResponseBase, new() { user = null; if (!WebApiRoot.UserSet.IsReadied) { string message = "服务器用户集启动中,请稍后"; response = ResponseBase.NotExist <TResponse>(message); return(false); } ClientSignData query = ClientSign; if (!Timestamp.IsInTime(query.Timestamp)) { response = ResponseBase.Expired <TResponse>(); return(false); } // 对于User来说LoginName可以是LoginName、Email、Mobile if (!string.IsNullOrEmpty(query.LoginName)) { user = WebApiRoot.UserSet.GetUser(UserId.Create(query.LoginName)); } if (user == null) { string message = "用户不存在"; response = ResponseBase.NotExist <TResponse>(message); return(false); } if (user.IsAdmin()) { response = null; return(true); } string mySign = RpcUser.CalcSign(user.LoginName, user.Password, query.Timestamp, data); if (query.Sign != mySign) { string message = "签名错误:1. 可能因为登录名或密码错误;2. 可能因为软件版本过期需要升级软件,请将软件升级到最新版本再试。"; response = ResponseBase.Forbidden <TResponse>(message); return(false); } response = null; return(true); }