mirror of
https://gitea.phreedom.club/localhost_frssoft/bloat.git
synced 2025-05-09 13:28:44 +00:00
Added sign up support. Tested on mastodon
But required test on GoToSocial. Confirmation inside bloat-fe not supported
This commit is contained in:
parent
f9702f81a9
commit
0f060f09c9
6 changed files with 244 additions and 2 deletions
|
@ -920,6 +920,72 @@ 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
|
||||
}
|
||||
|
||||
sid, err := util.NewSessionID()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
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{
|
||||
ID: sid,
|
||||
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) Post(c *client, content string, replyToID string,
|
||||
format string, visibility string, isNSFW bool, spoilerText string,
|
||||
files []*multipart.FileHeader, edit string) (id string, err error) {
|
||||
|
|
|
@ -254,6 +254,32 @@ func NewHandler(s *service, logger *log.Logger, 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")
|
||||
|
@ -786,6 +812,7 @@ func NewHandler(s *service, logger *log.Logger, staticDir string) http.Handler {
|
|||
r.HandleFunc("/settings", settingsPage).Methods(http.MethodGet)
|
||||
r.HandleFunc("/filters", filtersPage).Methods(http.MethodGet)
|
||||
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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue