mirror of
https://git.phreedom.club/localhost_frssoft/bloat.git
synced 2024-11-21 19:41:28 +00:00
remove unusable signup feature
This commit is contained in:
parent
1c3cb0f358
commit
6b3240dd9a
|
@ -92,50 +92,3 @@ func RegisterApp(ctx context.Context, appConfig *AppConfig) (*Application, error
|
|||
|
||||
return &app, nil
|
||||
}
|
||||
|
||||
type AppAuth struct {
|
||||
http.Client
|
||||
}
|
||||
|
||||
// RegisterApp make auth application and return app token.
|
||||
func AuthApp(ctx context.Context, appConfig *Application, instance string) (*string, error) {
|
||||
var appAuth AppAuth
|
||||
params := url.Values{}
|
||||
params.Set("client_id", appConfig.ClientID)
|
||||
params.Set("client_secret", appConfig.ClientSecret)
|
||||
params.Set("redirect_uris", "urn:ietf:wg:oauth:2.0:oob")
|
||||
params.Set("grant_type", "client_credentials")
|
||||
params.Set("scope", "read write follow")
|
||||
|
||||
u, err := url.Parse("https://" + instance)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
u.Path = path.Join(u.Path, "/oauth/token")
|
||||
|
||||
req, err := http.NewRequest(http.MethodPost, u.String(), strings.NewReader(params.Encode()))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
req = req.WithContext(ctx)
|
||||
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
||||
resp, err := appAuth.Do(req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, parseAPIError("bad request", resp)
|
||||
}
|
||||
|
||||
var res struct {
|
||||
AccessToken string `json:"access_token"`
|
||||
}
|
||||
err = json.NewDecoder(resp.Body).Decode(&res)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &res.AccessToken, nil
|
||||
}
|
||||
|
|
|
@ -982,66 +982,6 @@ func (s *service) Signin(c *client, code string) (err error) {
|
|||
return c.setSession(c.s)
|
||||
}
|
||||
|
||||
func (s *service) NewSessionRegister(c *client, instance string, reason string, username string, email string, password string, agreement bool, locale string, registerCredintals mastodon.RegisterCredintals) (rurl string, sess *model.Session, err error) {
|
||||
var instanceURL string
|
||||
if strings.HasPrefix(instance, "https://") {
|
||||
instanceURL = instance
|
||||
instance = strings.TrimPrefix(instance, "https://")
|
||||
} else {
|
||||
instanceURL = "https://" + instance
|
||||
}
|
||||
|
||||
csrf, err := util.NewCSRFToken()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
app, err := mastodon.RegisterApp(c.ctx, &mastodon.AppConfig{
|
||||
Server: instanceURL,
|
||||
ClientName: s.cname,
|
||||
Scopes: s.cscope,
|
||||
Website: s.cwebsite,
|
||||
RedirectURIs: s.cwebsite + "/oauth_callback",
|
||||
})
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
registerCredintals.App = app
|
||||
bearer, err := mastodon.AuthApp(c.ctx, app, instance)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
token, err := mastodon.RegisterAccount(c.ctx, instance, reason, username, email, password, agreement, locale, registerCredintals, *bearer)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
sess = &model.Session{
|
||||
Instance: instance,
|
||||
UserID: "1",
|
||||
ClientID: app.ClientID,
|
||||
ClientSecret: app.ClientSecret,
|
||||
AccessToken: *token,
|
||||
CSRFToken: csrf,
|
||||
Settings: *model.NewSettings(),
|
||||
}
|
||||
|
||||
u, err := url.Parse("/oauth/authorize")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
q := make(url.Values)
|
||||
q.Set("scope", "read write follow")
|
||||
q.Set("client_id", app.ClientID)
|
||||
q.Set("response_type", "code")
|
||||
q.Set("redirect_uri", s.cwebsite+"/oauth_callback")
|
||||
u.RawQuery = q.Encode()
|
||||
|
||||
rurl = instanceURL + u.String()
|
||||
return
|
||||
}
|
||||
|
||||
func (s *service) Signout(c *client) (err error) {
|
||||
return c.RevokeToken(c.ctx)
|
||||
}
|
||||
|
|
|
@ -293,32 +293,6 @@ func NewHandler(s *service, verbose bool, staticDir string) http.Handler {
|
|||
return nil
|
||||
}, NOAUTH, HTML)
|
||||
|
||||
signup := handle(func(c *client) error {
|
||||
instance := c.r.FormValue("instanceup")
|
||||
reason := c.r.FormValue("reason")
|
||||
username := c.r.FormValue("username")
|
||||
email := c.r.FormValue("email")
|
||||
password := c.r.FormValue("password")
|
||||
agreement := c.r.FormValue("agreement") == "true"
|
||||
locale := c.r.FormValue("locale")
|
||||
url, sess, err := s.NewSessionRegister(c, instance, reason, username, email, password, agreement, locale, mastodon.RegisterCredintals{
|
||||
Server: "https://"+instance,
|
||||
Reason: reason,
|
||||
Username: username,
|
||||
Email: email,
|
||||
Password: password,
|
||||
Agreement: agreement,
|
||||
Locale: locale,
|
||||
})
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
c.setSession(sess)
|
||||
url = "/confirmation"
|
||||
c.redirect(url)
|
||||
return nil
|
||||
}, NOAUTH, HTML)
|
||||
|
||||
oauthCallback := handle(func(c *client) error {
|
||||
q := c.r.URL.Query()
|
||||
token := q.Get("code")
|
||||
|
@ -856,7 +830,6 @@ func NewHandler(s *service, verbose bool, staticDir string) http.Handler {
|
|||
r.HandleFunc("/profile/delavatar", profileDelAvatar).Methods(http.MethodPost)
|
||||
r.HandleFunc("/profile/delbanner", profileDelBanner).Methods(http.MethodPost)
|
||||
r.HandleFunc("/signin", signin).Methods(http.MethodPost)
|
||||
r.HandleFunc("/signup", signup).Methods(http.MethodPost)
|
||||
r.HandleFunc("/oauth_callback", oauthCallback).Methods(http.MethodGet)
|
||||
r.HandleFunc("/post", post).Methods(http.MethodPost)
|
||||
r.HandleFunc("/like/{id}", like).Methods(http.MethodPost)
|
||||
|
|
|
@ -13,41 +13,6 @@
|
|||
<button type="submit"> Signin </button>
|
||||
</form>
|
||||
|
||||
<details>
|
||||
<summary>Sign up</summary>
|
||||
<p>
|
||||
<form class="signup-form" action="/signup" method="post">
|
||||
Enter the domain name of your instance to continue
|
||||
<br/>
|
||||
<input type="text" name="instanceup" placeholder="example.com" required>
|
||||
<br/>
|
||||
Enter the reason why you want register
|
||||
<br/>
|
||||
<textarea type="text" name="reason" cols="80" rows="3" required></textarea>
|
||||
<br/>
|
||||
The desired username for the account
|
||||
<br/>
|
||||
<input type="text" name="username" placeholder="exampleusernick" required>
|
||||
<br/>
|
||||
The email address to be used for login
|
||||
<br/>
|
||||
<input type="text" name="email" placeholder="example@example.com" required>
|
||||
<br/>
|
||||
The password to be used for login (Please use strong password!)
|
||||
<br/>
|
||||
<input type="password" name="password" required>
|
||||
<br/>
|
||||
You agrees to the terms, conditions, and policies of the instance
|
||||
<br/>
|
||||
<input type="checkbox" value="true" name="agreement" required>
|
||||
<input type="hidden" name="locale" value="en">
|
||||
<br/>
|
||||
<button type="submit"> Signup </button>
|
||||
</form>
|
||||
|
||||
</p>
|
||||
</details>
|
||||
|
||||
<p>
|
||||
See
|
||||
<a href="https://git.freesoftwareextremist.com/bloat" target="_blank">git.freesoftwareextremist.com/bloat</a>
|
||||
|
|
Loading…
Reference in a new issue