/// <summary> /// Validates player login data and closes sonnection /// </summary> public static bool EmailLogin(WebSocketSession session, XElement bodyXml) { Log.WriteLine("Email login from " + session.RemoteEndPoint, typeof(AccountsService)); // read user email string email = bodyXml.GetChildElement("Email")?.Value; // validate email from xml if (!AccountsUtil.EmailIsValid(email)) { // Send error info to player AccountsServerSend.Send_Error(session, AccountReturnCodes.NicknameIsInvalid, "Email is invalid"); return(false); } // check if account exist in database var user = DatabaseOperations.GetUserByEmail(email); if (user == null) { AccountsServerSend.Send_Error(session, AccountReturnCodes.NoSuchAccount); return(false); } // read password from xml string password = bodyXml.GetChildElement("Password")?.Value; // check password if (user.Password != password) { AccountsServerSend.Send_Error(session, AccountReturnCodes.WrongPassword); return(false); } // create auth token Token token = TokenManager.CreateTokenRegistredAccount(user); AccountsServerSend.Send_LoginOk(session, token); return(true); }