public void DataExportClientLogin(DataAdminMessageFactory.LoginMessage loginParams, UserModel tempUser) { if (!(Clients.GetAllItems().Exists(a => a.UserName == loginParams.UsernameMD5))) //if client not in list and he/she want to connected with dnet { AddClient(CurrentClient, loginParams.NetType, tempUser); //add client return; } var clientInList = Clients.GetAllItems().Find(a => a.UserName == loginParams.UsernameMD5); if (clientInList.IsDexportConnected == false) { clientInList.IsDexportConnected = true; clientInList.DexportProxy = CurrentClient.GetClientProxy <IDataAdminService>(); clientInList.DexportClient = CurrentClient; var usrModel = new UserModel(); if (OnloggedInLog != null) { var msg = new DataAdminMessageFactory.LogMessage { OperationStatus = DataAdminMessageFactory.LogMessage.Status.Finished, LogType = DataAdminMessageFactory.LogMessage.Log.Login, Time = DateTime.Now, UserID = tempUser.Id }; var msgMain = "Client " + usrModel.Name + " connected from " + CurrentClient.RemoteEndPoint; OnloggedInLog(msg, msgMain); } CurrentLoginTypeDexp = true; CurrentLoginTypeDnet = false; CurrentLoginTypeTnet = false; OnClientLogon(tempUser); } }
public void Login(DataAdminMessageFactory.LoginMessage loginParams) { if (loginFailed != null) { loginFailed(this, loginParams); } }
public void Login(DataAdminMessageFactory.LoginMessage loginParams) { var usr = loginParams.UsernameMD5; var psw = loginParams.PasswordMD5; string serverMessage = ""; string msgfail = ""; var users = AdminDatabaseManager.GetUsers(); if (users.Exists(a => a.Name == usr)) // if user in DB { UserModel tempUser = users.Find(a => a.Name == usr); if (tempUser.Password == psw) // if user psw == db.psw { string ipAddress = ""; var match = Regex.Match(CurrentClient.RemoteEndPoint.ToString(), @"\b(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})\b"); if (match.Success) { ipAddress = match.Captures[0].Value; } if ((ipAddress == tempUser.IpAdress && tempUser.AllowAnyIp == false) || (tempUser.AllowAnyIp)) // if with Ip adress is all good { #region VALIDATION if (loginParams.NetType == 'd' && tempUser.AllowDataNet == false) { serverMessage = "YOUR DATANET CLIENT BLOCKED BY ADMIN"; msgfail = "Client trying to connect from " + CurrentClient.RemoteEndPoint + " but his client blocked by Admin."; Error = true; } if (loginParams.NetType == 't' && tempUser.AllowTickNet == false) { serverMessage = "YOUR TICKNET CLIENT BLOCKED BY ADMIN"; msgfail = DateTime.Now.Date.ToShortDateString() + ": Client trying to connect from " + CurrentClient.RemoteEndPoint + " but his client blocked by Admin."; Error = true; } if (loginParams.NetType == 'e' && tempUser.AllowDexport == false) { serverMessage = "YOUR DATA EXPORT CLIENT BLOCKED BY ADMIN"; msgfail = DateTime.Now.Date.ToShortDateString() + ": Client trying to connect from " + CurrentClient.RemoteEndPoint + " but his client blocked by Admin."; Error = true; } #endregion #region Succes Login if (!Error) { if (loginParams.NetType == 'd' && tempUser.AllowDataNet) { DataNetClientLogin(loginParams, tempUser); } if (loginParams.NetType == 't' && tempUser.AllowTickNet) { TickNetClientLogin(loginParams, tempUser); } if (loginParams.NetType == 'e' && tempUser.AllowDexport) { DataExportClientLogin(loginParams, tempUser); } return; } #endregion } else { serverMessage = "YOUR IP ADDRESS IS NOT ALLOWED"; msgfail = DateTime.Now.Date.ToShortDateString() + ": Client trying connect to server from " + CurrentClient.RemoteEndPoint + " but the IP adress is blocked by Admin."; } } else { serverMessage = "ENTER A CORRECT PASSWORD"; } } else { serverMessage = "YOUR USERNAME IS INCORRECT"; } #region Create Server Message about failed login and send to client if (OnloginFailedLog != null) { new Thread(() => OnloginFailedLog(new DataAdminMessageFactory.LogMessage(), msgfail)).Start(); } var client = CurrentClient; //Get a proxy object to call methods of client when needed var clientProxy = client.GetClientProxy <IDataAdminService>(); var loginFailed = new DataAdminMessageFactory.LoginMessage("", "", 'd') { ServerMessage = serverMessage }; clientProxy.Login(loginFailed); #endregion }