Esempio n. 1
0
        public ActionResult <RetroColumn> PostRetroColumn(RetroColumn retroColumn)
        {
            Retrospective retrospective = _context.Retrospectives.First(x => x.Id == retroColumn.RetrospectiveId);

            var decodedId = decoder.DecodeToken(Request != null ? (Request.Headers.ContainsKey("token") ? Request.Headers["token"].ToString() : null) : null);

            if (retrospective == null && retroColumn != null)
            {
                return(NotFound());
            }

            if (decodedId == null || retrospective.RetroUserId != int.Parse(decodedId))
            {
                return(Unauthorized());
            }

            _context.SaveRetroColumn(retroColumn);

            if (_hubContext.Clients != null)
            {
                try
                {
                    _hubContext.Clients.All.BroadcastMessage(true, retroColumn.RetrospectiveId);
                }
                catch (Exception e)
                {
                    _hubContext.Clients.All.BroadcastMessage(false, retroColumn.RetrospectiveId);
                }
            }

            return(CreatedAtAction("GetRetroColumn", new { id = retroColumn.Id }, retroColumn));
        }
        public async Task <ActionResult <IEnumerable <Retrospective> > > GetRetrospectives()
        {
            var id = decoder.DecodeToken(Request != null ? (Request.Headers.ContainsKey("token") ? Request.Headers["token"].ToString() : null) : null);

            if (id == null)
            {
                return(Unauthorized());
            }

            return(await Task.FromResult(_context.GetAll().Where(x => x.RetroUserId == int.Parse(id)).ToList()));
        }
Esempio n. 3
0
        public async Task <ActionResult> UpdatePassword(string token, [FromBody] UpdatePasswordViewModel passwordViewModel)
        {
            // First checktoken
            // TODO: Add token check
            var retroUserId = decoder.DecodeToken(token);

            var retroUser = await userManager.FindByIdAsync(retroUserId);

            if (retroUser != null)
            {
                var result = await userManager.RemovePasswordAsync(retroUser);

                if (result.Succeeded)
                {
                    result = await userManager.AddPasswordAsync(retroUser, passwordViewModel.Password);

                    if (result.Succeeded)
                    {
                        return(Ok(new
                        {
                            message = MessageConstants.ResetPasswordOk
                        }));
                    }
                }
                else
                {
                    return(BadRequest(new
                    {
                        message = MessageConstants.ResetPasswordError
                    }));
                }
            }

            return(BadRequest(new
            {
                message = MessageConstants.ResetPasswordBad
            }));
        }