public IActionResult Logout() { HttpServiceUriBuilder contextUri = new HttpServiceUriBuilder().SetServiceName(this.context.ServiceName); // Manage session if (!HTTPHelper.IsSessionExpired(HttpContext, this)) { HTTPHelper.EndSession(HttpContext, this); } ViewBag.RedirectURL = contextUri.GetServiceNameSiteHomePath(); return(Ok(contextUri.GetServiceNameSiteHomePath())); }
public ActionResult Login(UserProfile objUser) { // Manage session and Context HttpServiceUriBuilder contextUri = new HttpServiceUriBuilder().SetServiceName(this.context.ServiceName); if (ModelState.IsValid) { ViewBag.Message = ""; ViewBag.RedirectURL = ""; bool newUserRegistration = false; bool userAllowedToLogin = false; if ((objUser.Password != null && objUser.Password.Length > 0)) { // First let deal to see if this a user registration if (objUser.FirstName != null) { newUserRegistration = true; Task <bool> result = RESTHandler.ExecuteFabricPOSTForEntity(typeof(UserProfile), Names.InsightDataServiceName, "api/entities/user/withIdentity/" + objUser.UserName, "user", objUser, this.context, this.httpClient, this.appLifetime.ApplicationStopping, ServiceEventSource.Current); if (result.Result) { userAllowedToLogin = true; } else { ViewBag.RedirectURL = contextUri.GetServiceNameSiteHomePath(); ViewBag.Message = "Error during new user registration - User already exist in the database"; } } if (!userAllowedToLogin && !newUserRegistration) { Task <object> userObject = RESTHandler.ExecuteFabricGETForEntity(typeof(UserProfile), Names.InsightDataServiceName, "api/entities/user/byIdentity/" + objUser.UserName, "user", this.context, this.httpClient, this.appLifetime.ApplicationStopping, ServiceEventSource.Current); if (userObject != null) { UserProfile userProfile = (UserProfile)userObject.Result; if (objUser.Password.Equals(userProfile.Password)) { userAllowedToLogin = true; } else { ViewBag.RedirectURL = contextUri.GetServiceNameSiteHomePath(); ViewBag.Message = "Invalid Username and/or Password"; } } else { ViewBag.RedirectURL = contextUri.GetServiceNameSiteHomePath(); ViewBag.Message = "Error checking user credentials"; } } if (userAllowedToLogin) { try { string redirectTo = HTTPHelper.StartSession(HttpContext, this, objUser, "User", "/api/devices", contextUri.GetServiceNameSiteHomePath()); //TODO : make the redirection configurable as part of insight application return(Redirect(redirectTo)); } catch (System.Exception ex) { ViewBag.RedirectURL = contextUri.GetServiceNameSiteHomePath(); ViewBag.Message = "Internal Error During User Login- Report to the System Administrator"; Console.WriteLine("On Login Session exception msg=[" + ex.Message + "]"); } } } else { ViewBag.RedirectURL = contextUri.GetServiceNameSiteHomePath(); ViewBag.Message = "Either username and/or password not provided"; } } if (!HTTPHelper.IsSessionExpired(HttpContext, this)) { HTTPHelper.EndSession(HttpContext, this); } return(View("Index", objUser)); }