Exemplo n.º 1
0
        public HttpResponseMessage ChangeUser([FromBody] UserModel user)
        {
            var dateStart = DateTime.Now;

            _performancelog.Debug($"Start,LoginController,ChangeUser,{string.Empty},{DateTime.Now:hh.mm.ss.ffffff}");
            var accessToken = Request.GetFirstHeaderValueOrDefault <string>("authToken");
            var userCode    = TokenValidator.GetUserCode(accessToken);

            if (user != null)
            {
                ErrorMessage errorMessage;
                string       userName;
                var          result = _loginManager.ChangeUser(userCode, user.UserName,
                                                               user.Password, user.TillNumber, user.ShiftNumber, user.ShiftDate,
                                                               user.PosId, user.UnauthorizedAccess, out errorMessage, out userName);
                if (!string.IsNullOrEmpty(errorMessage.MessageStyle.Message) || !result)
                {
                    var response = new InvalidLoginReponseModel
                    {
                        Error       = errorMessage.MessageStyle,
                        ShutDownPOS = false
                    };
                    return(Request.CreateResponse(HttpStatusCode.Conflict, response));
                }
                var ticks         = DateTime.Now.Ticks;
                var token         = TokenGenerator.GenerateToken(user.UserName, ticks, user.PosId);
                var loginResponse = new LoginResponseModel
                {
                    AuthToken      = token,
                    TrainerCaption = userName
                };
                return(Request.CreateResponse(HttpStatusCode.OK, loginResponse));
            }

            _performancelog.Debug($"End,LoginController,ChangeUser,{DateTime.Now.Subtract(dateStart).TotalMilliseconds},{DateTime.Now:hh.mm.ss.ffffff}");
            var error = new InvalidLoginReponseModel
            {
                Error = new MessageStyle
                {
                    Message     = Resource.InvalidInformation,
                    MessageType = MessageType.OkOnly
                },
                ShutDownPOS = true
            };

            return(Request.CreateResponse(HttpStatusCode.BadRequest, error));
        }