Exemple #1
0
    protected void gvMyServices_RowUpdating(object sender, GridViewUpdateEventArgs e)
    {
        if (e == null)
        {
            throw new ArgumentNullException("e");
        }

        MFBOauth2Client client = new List <MFBOauth2Client>(OwnedClients)[e.RowIndex];

        client.ClientSecret = (string)e.NewValues["ClientSecret"];
        client.ClientName   = (string)e.NewValues["ClientName"];
        client.Callback     = (string)e.NewValues["Callback"];
        client.Scope        = (string)e.NewValues["Scope"];
        try
        {
            MFBOauthServer.ScopesFromString(client.Scope);  // will throw an exception for an invalid scope.
            client.Commit();
            gvMyServices.EditIndex  = -1;
            OwnedClients            = null; // force a refresh.
            gvMyServices.DataSource = OwnedClients;
            gvMyServices.DataBind();
        }
        catch (UnauthorizedAccessException ex)
        {
            lblErrGV.Text = ex.Message;
        }
        catch (MyFlightbookValidationException ex)
        {
            lblErrGV.Text = ex.Message;
        }
        catch (ArgumentOutOfRangeException ex)
        {
            lblErrGV.Text = ex.Message;
        }
    }
Exemple #2
0
    protected void btnAddClient_Click(object sender, EventArgs e)
    {
        Page.Validate("newClient");
        if (Page.IsValid)
        {
            List <string> lst = new List <string>();
            foreach (ListItem li in cklScopes.Items)
            {
                if (li.Selected)
                {
                    lst.Add(li.Value);
                }
            }
            string          szScopes = String.Join(",", lst);
            MFBOauth2Client client   = new MFBOauth2Client(txtClient.Text, txtSecret.Text, "https://" + txtCallback.Text, txtName.Text, szScopes, Page.User.Identity.Name);
            try
            {
                MFBOauthServer.ScopesFromString(szScopes); // will throw an exception for an invalid scope.
                client.Commit();                           // will throw any exception.
                OwnedClients            = null;            // force a refresh.
                gvMyServices.DataSource = OwnedClients;
                gvMyServices.DataBind();
                txtCallback.Text = txtClient.Text = txtName.Text = txtSecret.Text = string.Empty;
                foreach (ListItem li in cklScopes.Items)
                {
                    li.Selected = false;
                }
                Expando.ExpandoControl.Collapsed = true;

                util.NotifyAdminEvent("oAuth client created", String.Format(CultureInfo.CurrentCulture, "User: {0}, Name: {1}", Page.User.Identity.Name, client.ClientName), ProfileRoles.maskCanReport);
            }
            catch (UnauthorizedAccessException ex)
            {
                lblErr.Text = ex.Message;
            }
            catch (MyFlightbookValidationException ex)
            {
                lblErr.Text = ex.Message;
            }
            catch (ArgumentOutOfRangeException ex)
            {
                lblErr.Text = ex.Message;
            }
        }
    }
 protected void gvOAuthClients_RowDataBound(object sender, GridViewRowEventArgs e)
 {
     if (e == null)
     {
         throw new ArgumentNullException("e");
     }
     if (e.Row.RowType == DataControlRowType.DataRow)
     {
         MFBOauthClientAuth oauth = (MFBOauthClientAuth)e.Row.DataItem;
         if (oauth.Scope != null)
         {
             IEnumerable <string> lstScopes = MFBOauthServer.ScopeDescriptions(MFBOauthServer.ScopesFromString(oauth.Scope));
             ((MultiView)e.Row.FindControl("mvScopesRequested")).SetActiveView(lstScopes.Count() == 0 ? ((View)e.Row.FindControl("vwNoScopes")) : ((View)e.Row.FindControl("vwRequestedScopes")));
             Repeater rpt = (Repeater)e.Row.FindControl("rptPermissions");
             rpt.DataSource = lstScopes;
             rpt.DataBind();
         }
     }
 }