Exemple #1
0
        private OperationResponse LoginViaSteam(LoginOperationRequest operation)
        {
            SteamId     steamId = new SteamId(operation.login);
            DbUserLogin user    = application.GetUser(steamId);

            if (user == null)
            {
                s_Log.InfoFormat("Create new user for steam id: {0}", steamId);
                user = application.DbUserLogins.CreateUser(steamId);
            }
            else
            {
                s_Log.InfoFormat("User with steam id: {0} already exists in database, ok", steamId);
            }

            string platform = GetPlatform(operation);

            LoginOperationResponse response = new LoginOperationResponse {
                facebookId  = user.facebookId,
                GameRefId   = user.gameRef,
                Login       = user.login,
                returnCode  = (int)LoginReturnCode.Ok,
                vkontakteId = user.vkontakteId,
                method      = (byte)LoginMethod.steam,
                deviceId    = string.Empty
            };

            AddUserToCollection(user, platform);
            return(new OperationResponse(operation.OperationRequest.OperationCode, response));
        }
Exemple #2
0
        private OperationResponse LoginViaVkontakte(LoginOperationRequest operation)
        {
            VkontakteId vkontakteId = new VkontakteId(operation.vkontakteId);
            DbUserLogin user        = application.GetUser(vkontakteId);

            if (user == null)
            {
                user = application.DbUserLogins.CreateUser(vkontakteId);
            }

            string platform = GetPlatform(operation);

            LoginOperationResponse response = new LoginOperationResponse {
                facebookId  = string.Empty,
                GameRefId   = user.gameRef,
                Login       = user.login,
                returnCode  = (int)LoginReturnCode.Ok,
                vkontakteId = user.vkontakteId,
                method      = (byte)LoginMethod.vkontakte,
                deviceId    = string.Empty
            };

            AddUserToCollection(user, platform);

            return(new OperationResponse(operation.OperationRequest.OperationCode, response));
        }
Exemple #3
0
 public UserLogin(DbUserLogin dbUserLogin)
 {
     UserLoginId  = dbUserLogin.DbUserLoginId;
     PasswordHash = dbUserLogin.PasswordHash;
     UserId       = dbUserLogin.UserId;
     User         = new User(dbUserLogin.DbUser);
 }
        private string ComposeMailMessageBody(DbUserLogin user, string language)
        {
            switch (language)
            {
            case "ru":
                return(string.Format("Здесь данные аккаунта, привязанного к этой почте в игре Туманность Онлайн{0}Логин: {1}{0}Пароль: {2}{0}Ждем Вас в игре!",
                                     Environment.NewLine, user.login, user.password));

            default:
                return(string.Format("Here accaunt data for this email at game Nebula Online{0}Login: {1}{0}Password: {2}{0}Wait you in game!",
                                     Environment.NewLine, user.login, user.password));
            }
        }
Exemple #5
0
        private void AddUserToCollection(DbUserLogin user, string platform)
        {
            FullUserAuth fullAuth = new FullUserAuth(user.login, user.gameRef, user.facebookId, user.vkontakteId, user.deviceId);

            (peer as LoginClientPeer).SetLogin(new LoginId(fullAuth.login));
            application.LogedInUsers.OnUserLoggedIn(fullAuth, peer as LoginClientPeer);
            application.stats.OnUserLoggedIn(fullAuth, platform);
            if (user != null)
            {
                user.IncrementSessionCount();
                user.UpdateLastSessionTime();
                application.SaveUser(user);
            }
        }
        public override OperationResponse Handle(OperationRequest request, SendParameters sendParameters)
        {
            RecoverUserRequest operation = new RecoverUserRequest(peer.Protocol, request);

            if (!operation.IsValid)
            {
                return(new OperationResponse(request.OperationCode)
                {
                    ReturnCode = (short)ReturnCode.InvalidOperationParameter,
                    DebugMessage = operation.GetErrorMessage()
                });
            }

            RegexUtilities emailChecker = new RegexUtilities();

            if (!emailChecker.IsValidEmail(operation.email))
            {
                RecoverUserResponse responseObject = new RecoverUserResponse {
                    returnCode = (int)LoginReturnCode.EmailInvalid
                };
                return(new OperationResponse(request.OperationCode, responseObject));
            }

            var         database = application.DbUserLogins;
            DbUserLogin dbUser   = database.GetUser(new Email(operation.email));

            if (dbUser == null)
            {
                RecoverUserResponse responseObject = new RecoverUserResponse {
                    returnCode = (int)LoginReturnCode.UserNotFound
                };
                return(new OperationResponse(request.OperationCode, responseObject));
            }

            EmailSender sender = new EmailSender(SMTP_SERVER, SMTP_SERVER_PORT, SOURCE_USER, SOURCE_PASSWORD);
            string      title  = ComposeMailMessageTitle(operation.language);
            string      body   = ComposeMailMessageBody(dbUser, operation.language);


            task = Task.Factory.StartNew(() => {
                bool result = sender.SendMessage(dbUser.email, title, body);
                log.InfoFormat("message sended with status = {0}", result);
            });

            RecoverUserResponse successResponseObject = new RecoverUserResponse {
                returnCode = (int)LoginReturnCode.Ok
            };

            return(new OperationResponse(request.OperationCode, successResponseObject));
        }
Exemple #7
0
        public UserLogin AddUserLogin(UserLogin userLogin)
        {
            var dbContext   = new DataContext();
            var dbUserLogin = new DbUserLogin();

            dbUserLogin.DbUserLoginId = userLogin.UserLoginId;
            dbUserLogin.UserId        = userLogin.UserId;
            dbUserLogin.PasswordHash  = userLogin.PasswordHash;
            dbUserLogin.DbUser        = new UsersRepository().GetDbUser(dbContext, userLogin.User.UserId);

            dbUserLogin = dbContext.DbUserLogins.Add(dbUserLogin);
            dbContext.SaveChanges();

            return(new UserLogin(dbUserLogin));
        }
Exemple #8
0
        private OperationResponse LoginViaServer(LoginOperationRequest operation)
        {
            string      password  = StringChiper.Decrypt(operation.encryptedPassword);
            LoginAuth   loginAuth = new LoginAuth(operation.login, password);
            DbUserLogin user      = application.GetUser(loginAuth);

            string platform = GetPlatform(operation);

            LoginOperationResponse response = null;

            if (user == null)
            {
                response = new LoginOperationResponse {
                    facebookId  = operation.facebookId,
                    GameRefId   = string.Empty,
                    Login       = operation.login,
                    method      = (byte)LoginMethod.server,
                    returnCode  = (int)LoginReturnCode.UserNotFound,
                    vkontakteId = operation.vkontakteId,
                    deviceId    = string.Empty
                };
            }
            else
            {
                response = new LoginOperationResponse {
                    facebookId  = user.facebookId,
                    GameRefId   = user.gameRef,
                    Login       = user.login,
                    method      = (byte)LoginMethod.server,
                    returnCode  = (int)LoginReturnCode.Ok,
                    vkontakteId = user.vkontakteId,
                    deviceId    = string.Empty
                };
                AddUserToCollection(user, platform);
            }
            return(new OperationResponse(operation.OperationRequest.OperationCode, response));
        }
Exemple #9
0
        public static void InsertTestData(TestDbContext ctx)
        {
            if (ctx.UserLogins.FirstOrDefault(u => u.Id == 1) != null)
            {
                return;
            }

            var userLogin = new DbUserLogin()
            {
                Initials          = "TE",
                UserPrincipalName = "*****@*****.**",
                DisplayName       = "Test user"
            };

            ctx.UserLogins.Add(userLogin);

            var entityType = new DbEntityType()
            {
                Description         = "Test",
                TableName           = "TEST",
                CreatedAt           = DateTime.Now,
                CreatedByUserLogin  = userLogin,
                ModifiedAt          = DateTime.Now,
                ModifiedByUserLogin = userLogin
            };

            ctx.EntityTypes.Add(entityType);

            var cir = new DbCIR()
            {
                Code        = "C1",
                Description = "D1",

                CreatedAt           = DateTime.Now,
                CreatedByUserLogin  = userLogin,
                ModifiedAt          = DateTime.Now,
                ModifiedByUserLogin = userLogin
            };

            ctx.CIRs.Add(cir);

            for (int i = 0; i < 10; i++)
            {
                ctx.Entities.Add(new DbEntity()
                {
                    Code                = $"C{i}",
                    Description         = $"D{i}",
                    EntityKey           = 123,
                    EntityType          = entityType,
                    IsActive            = true,
                    CreatorCIR          = cir,
                    MasterCIR           = cir,
                    CreatedAt           = DateTime.Now,
                    CreatedByUserLogin  = userLogin,
                    ModifiedAt          = DateTime.Now,
                    ModifiedByUserLogin = userLogin
                });
            }

            ctx.SaveChanges();
        }