コード例 #1
0
        public HttpResponseMessage Login([FromBody] LoginModel loginModel)
        {
            string         email    = loginModel.email;
            string         password = loginModel.password;
            CustomResponse response;
            User           loginUser = _repository.Login(loginModel);

            if (loginUser != null)
            {
                //LoginUser
                var userToken = new UserTokenDTO()
                {
                    email      = email,
                    password   = password,
                    expireDate = DateTime.Now.AddDays(TOKEN_EXPIRE_DAY)
                };

                //Serializing userToken
                var jsonString = JsonConvert.SerializeObject(userToken);
                // Token generation
                var token = FTH.Extension.Encrypter.Encrypt(jsonString, LoginUtility.PRIVATE_KEY);

                LoginResponseDTO userDTO = GenericMapper.MapToLoginResponseDTO(loginUser, token);

                response = ResponseMessageHelper.CreateResponse(HttpStatusCode.OK, false, userDTO, ConstantResponse.LOGIN_SUCCESS);
                return(Request.CreateResponse <CustomResponse>(HttpStatusCode.OK, response));
            }
            else
            {
                response = ResponseMessageHelper.CreateResponse(HttpStatusCode.Unauthorized, true, null, ConstantResponse.LOGIN_FAILED);
                return(Request.CreateResponse <CustomResponse>(HttpStatusCode.Unauthorized, response));
            }
        }