Example #1
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));
        }
Example #2
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));
        }
Example #3
0
        public async Task <LoginOperationResponse> Execute(LoginOperationRequest request)
        {
            var checkResponse = await _checkUserCredentialsOperation.Execute(new CheckUserCredentialsOperationRequest
                                                                             { Email = request.Email, Password = request.Password });

            if (!checkResponse.IsCorrect)
            {
                return(new LoginOperationResponse
                {
                    IsAuthenticated = false
                });
            }

            var jwtResponse = _createJwtOperation.Execute(new CreateJwtOperationRequest {
                Email = request.Email
            });


            return(new LoginOperationResponse
            {
                IsAuthenticated = true,
                Token = jwtResponse.Token,
                Expires = jwtResponse.Expires
            });
        }
Example #4
0
        private string GetPlatform(LoginOperationRequest operation)
        {
            string platform = string.Empty;

            if (operation.platform != null)
            {
                platform = operation.platform;
            }
            return(platform);
        }
        public async Task <ActionResult <JwtModel> > Login([FromBody] LoginModel model)
        {
            var loginRequest = new LoginOperationRequest
            {
                Email = model.Email, Password = model.Password
            };

            var authenticationResult = await _loginOperation.Execute(loginRequest);

            if (authenticationResult.IsAuthenticated)
            {
                var tokenModel = new JwtModel
                {
                    Token   = authenticationResult.Token,
                    Expires = authenticationResult.Expires
                };

                return(Ok(tokenModel));
            }

            return(Unauthorized());
        }
Example #6
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));
        }
Example #7
0
        public override OperationResponse Handle(OperationRequest request, SendParameters sendParameters)
        {
            LoginOperationRequest operation = new LoginOperationRequest(peer.Protocol, request);

            if (!operation.IsValid)
            {
                return(new OperationResponse(request.OperationCode)
                {
                    ReturnCode = (short)ReturnCode.OperationInvalid,
                    DebugMessage = "Login operation parameters invalid"
                });
            }

            if (operation.login != null)
            {
                operation.login = operation.login.ToLower();
            }

            OperationResponse response    = null;
            LoginMethod       loginMethod = LoginMethod.device_id;

            if (operation.TryGetLoginMethod(out loginMethod))
            {
                if (loginMethods.ContainsKey(loginMethod))
                {
                    response = loginMethods[loginMethod](operation);
                }
                else
                {
                    s_Log.InfoFormat("Login methods dictionary don't  contains {0}", loginMethod);
                }
            }
            else
            {
                s_Log.InfoFormat("Error of parse login method {0}", operation.method);
            }

            /*
             * if(operation.method == (byte)LoginMethod.server) {
             *  response = LoginViaServer(operation);
             * } else if( operation.method == (byte)LoginMethod.facebook ) {
             *  response = LoginViaFacebook(operation);
             * } else if( operation.method == (byte)LoginMethod.vkontakte ) {
             *  response = LoginViaVkontakte(operation);
             * } else if(operation.method == (byte)LoginMethod.steam ) {
             *  response = LoginViaSteam(operation);
             * }*/

            if (response != null)
            {
                return(response);
            }
            else
            {
                s_Log.Info("Login error occured...");
                LoginOperationResponse data = new LoginOperationResponse {
                    facebookId  = operation.facebookId,
                    GameRefId   = string.Empty,
                    Login       = operation.login,
                    method      = operation.method,
                    returnCode  = (int)LoginReturnCode.UnknownError,
                    vkontakteId = operation.vkontakteId,
                    deviceId    = operation.deviceId
                };
                return(new OperationResponse(operation.OperationRequest.OperationCode, data));
            }
        }