Esempio n. 1
0
        public async Task <RES_LOGIN> Process(REQ_LOGIN requestPacket)
        {
            var responseResult = new RES_LOGIN();

            var userObject = await UserRepository.GetUser(requestPacket.UserID);

            if (userObject == null)
            {
                return(responseResult.Return(ERROR_CODE.REQ_LOGIN_INVALID_USER));
            }

            if (userObject.PW != requestPacket.PW)
            {
                return(responseResult.Return(ERROR_CODE.REQ_LOGIN_PW));
            }
            //시간은 좋지 않다. https://paragonie.com/blog/2016/05/how-generate-secure-random-numbers-in-various-programming-languages

            var authToken = System.DateTime.Now.Ticks.ToString();
            //레디스에 등록하기 전에 확인을 해보거나
            await AuthTokenRepository.Add(requestPacket.UserID, authToken);

            responseResult.SetResult(ERROR_CODE.NONE);
            responseResult.AuthToken = authToken;
            return(responseResult);
        }
Esempio n. 2
0
        public async Task <RES_LOGIN> Process(REQ_LOGIN requestPacket)
        {
            var responseResult = new RES_LOGIN();

            var userData = await Data.UserRepository.GetUser(requestPacket.UserID);

            // user가 없다면 새로운 유저를 생성해줌.

            if (userData == null)
            {
                responseResult.Return(ERROR_CODE.REQ_LOGIN_GET_USER_ERROR);
            }

            if (userData.Rows.Count == 0)
            {
                var createResult = await Data.UserRepository.CreateUser(requestPacket.UserID, requestPacket.PW);

                if (createResult.Item1 != 1)
                {
                    responseResult.Return(ERROR_CODE.REQ_LOGIN_CREATE_ERROR);
                }

                responseResult.Pokemon = (short)createResult.Item2;
                responseResult.Chip    = Program.StartMoney;
                responseResult.SetResult(ERROR_CODE.REQ_LOGIN_CREATE_SUCCESS);
            }
            else
            {
                if (userData.Rows[0]["pw"].ToString() != requestPacket.PW)
                {
                    return(responseResult.Return(ERROR_CODE.REQ_LOGIN_INVALID_PW));
                }
                responseResult.Pokemon = (short)Int32.Parse(userData.Rows[0]["pokemon"].ToString());
                responseResult.Chip    = (short)Int32.Parse(userData.Rows[0]["chip"].ToString());
                responseResult.SetResult(ERROR_CODE.NONE);
            }

            responseResult.Channels = await Data.UserRepository.GetChannel();

            Guid   g         = Guid.NewGuid();
            string authToken = Convert.ToBase64String(g.ToByteArray());
            //authToken = authToken.Replace("=", "");
            //authToken = authToken.Replace("+", "");
            //authToken = authToken.Replace("/", "");

            int affectedRows = await Data.UserRepository.SaveAuthToken(authToken, requestPacket.UserID);

            if (affectedRows == 0)
            {
                responseResult.Return(ERROR_CODE.REQ_LOGIN_AUTH_DUPLICATE);
            }

            responseResult.AuthToken = authToken;
            return(responseResult);
        }
Esempio n. 3
0
        public async Task <RES_LOGIN> Process(REQ_LOGIN requestPacket)
        {
            var responseResult = new RES_LOGIN();

            var userObject = await UserRepository.GetUser(requestPacket.UserID);

            if (userObject == null)
            {
                return(responseResult.Return(ERROR_CODE.REQ_LOGIN_INVALID_USER));
            }

            if (userObject.PW != requestPacket.PW)
            {
                return(responseResult.Return(ERROR_CODE.REQ_LOGIN_PW));
            }

            var authToken = System.DateTime.Now.Ticks.ToString();
            await AuthTokenRepository.Add(requestPacket.UserID, authToken);

            responseResult.SetResult(ERROR_CODE.NONE);
            responseResult.AuthToken = authToken;
            return(responseResult);
        }