internal static string GetUserRedirect(LoginModel model) { WebMatrix.WebData.SimpleRoleProvider roleProvider = new WebMatrix.WebData.SimpleRoleProvider(); string redirect_url = ""; string[] roles = roleProvider.GetRolesForUser(model.UserName); foreach (string role in roles) { switch (role.ToLower()) { case "administrator": redirect_url = "Admin/Dashboard"; break; case "customer" : redirect_url = "Site/Dashboard"; break; default : redirect_url = "Site/Dashboard"; break; } } return redirect_url; }
public string GetAuthKey(string authData) { string[] credentials = ParseAuthHeaders(authData); if (credentials == null && credentials.Length <= 1) throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotAcceptable)); if (!WebMatrix.WebData.WebSecurity.UserExists(credentials[0])) throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.NotFound)); if (WebMatrix.WebData.WebSecurity.Login(credentials[0], credentials[1])) { if (System.Web.HttpContext.Current != null && System.Web.HttpContext.Current.Session != null && System.Web.HttpContext.Current.Session["_MyAppSession"] != null) { WebMatrix.WebData.SimpleRoleProvider provider = new WebMatrix.WebData.SimpleRoleProvider(); int userId = -1; if (WebMatrix.WebData.WebSecurity.IsAuthenticated) userId = WebMatrix.WebData.WebSecurity.GetUserId(WebMatrix.WebData.WebSecurity.CurrentUserName); else userId = WebMatrix.WebData.WebSecurity.GetUserId(credentials[0]); AuthClientData client = new AuthClientData(); client.IpAddress = GetIpAddress(); client.MachineName = DetermineCompName(client.IpAddress); string token = AuthTokenManagerEx.Instance.Generate(client); AuthTokenManagerEx.Instance[client].UserId = userId; return token; } else throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.InternalServerError)); } throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)); }