public IActionResult ActivateAccount([FromQuery] string token) { bool TokenIsValid = jwt.ValidateCurrentToken(token); if (TokenIsValid) { int userId = int.Parse(jwt.GetId(token)); User user = db.Users.Include(x => x.ProfilePhotos).Where(s => s.Id == userId).FirstOrDefault(); if (!user.IsActive) { user.IsActive = true; db.Users.Update(user); db.SaveChanges(); userData.SetUser(HttpContext, user); } } return(RedirectToAction("Register", "Account")); }
public void OnActionExecuting(ActionExecutingContext context) { try { Microsoft.Extensions.Primitives.StringValues token; context.HttpContext.Request.Headers.TryGetValue("token", out token); if (!_jwt.ValidateCurrentToken(token)) { context.Result = new RedirectToRouteResult( new RouteValueDictionary { { "controller", "Account" }, { "action", "NotAuthoriced" } }); return; } int userId = int.Parse(_jwt.GetId(token)); string controllerName = context.RouteData.Values["controller"].ToString(); string actionName = context.RouteData.Values["action"].ToString(); string url = "/" + controllerName + "/" + actionName; List <string> abilities; if (userAbilities.ContainsKey(userId)) { abilities = userAbilities[userId]; } else { abilities = _eyadtakDbContext.Users_Roles.Where(x => x.UserId == userId).Include(x => x.Role).SelectMany(x => x.Role.Role_Ability).Select(x => x.Ability.Url).ToList(); userAbilities.TryAdd(userId, abilities); } if (!abilities.Where(s => s == url).Any()) { context.Result = new RedirectToRouteResult( new RouteValueDictionary { { "controller", "Account" }, { "action", "NotAuthoriced" } }); return; } context.HttpContext.Items.Add("userId", userId); } catch (Exception e) { context.Result = new RedirectToRouteResult( new RouteValueDictionary { { "controller", "Account" }, { "action", "NotAuthoriced" } }); return; throw e; } }
public IActionResult ActivateAccount([FromQuery] string token) { try { if (!_jwt.ValidateCurrentToken(token)) { return(Ok(new { message = "Token is not valid", ErrorHappen = true })); } int userId = int.Parse(_jwt.GetId(token)); User user = _eyadtakDbContext.Users.FirstOrDefault(x => x.UserId == userId); user.Active = true; _eyadtakDbContext.Users.Update(user); _eyadtakDbContext.SaveChanges(); return(Ok(new { message = "Activation done successfully", ErrorHappen = false })); } catch (Exception e) { return(Ok(new { message = "Something went wrong", ErrorHappen = true })); throw e; } }