ActionResult AuthorizeUser(string claimedUserId, string ticket, string returnUrl, string userEmail = null, string userName = null) { bool updating = !string.IsNullOrEmpty(ticket); User user = CurrentServiceModel.GetUserFromOpenId(claimedUserId); if (updating) { if (user == null) { ViewData["Message"] = "User not registered"; return(View("Login")); } string newId = GetTicketId(ticket); CurrentServiceModel.UpdateOpenId(claimedUserId, newId); FormsAuthentication.SignOut(); } // Try to migrate users using old Google OpenID to OAuth2 if (user == null && !string.IsNullOrEmpty(userEmail)) { var currentUser = CurrentServiceModel.GetUserByEmail(userEmail); if (currentUser != null && currentUser.OpenId.StartsWith("https://www.google.com/accounts/o8/id")) { CurrentServiceModel.UpdateOpenId(currentUser.OpenId, claimedUserId); user = currentUser; } } // This is a new user, send them to a registration page if (user == null) { ViewData["openid"] = claimedUserId; if (Settings.Default.SupportsMultiApps) { return(Redirect(string.Format("~/home/User/register?openid={0}&name={1}&email={2}", Url.Encode(claimedUserId), Url.Encode(userName), Url.Encode(userEmail)))); } else { return(Redirect(string.Format("~/User/register?openid={0}&name={1}&email={2}", Url.Encode(claimedUserId), Url.Encode(userName), Url.Encode(userEmail)))); } } FormsAuthentication.SetAuthCookie(user.Login, false); if (!string.IsNullOrEmpty(returnUrl)) { return(Redirect(returnUrl)); } else if (updating) { return(Redirect(ControllerHelper.GetActionUrl("home", "Index", "Home"))); } else { return(RedirectToAction("Index", "Home")); } }
public ActionResult AddOwnerAsync(int id, string email) { CurrentUserModel.ValidateProject(id); User u = CurrentServiceModel.GetUserByEmail(email); if (u != null) { CurrentUserModel.AddProjectOwner(id, u.Id); return(Content("OK")); } else { return(Content("")); } }
public ActionResult AddAdminAsync(string email) { CurrentUserModel.CheckIsAdmin(); User u = CurrentServiceModel.GetUserByEmail(email); if (u != null) { CurrentUserModel.SetUserApplicationPermission(u.Id, ApplicationPermission.Administer, true); return(Content("OK")); } else { return(Content("")); } }