Improved twitter login

This commit is contained in:
Eduard Urbach 2019-03-05 15:44:48 +09:00
parent 35c7aaaa24
commit f572a08888
2 changed files with 21 additions and 12 deletions

View File

@ -17,9 +17,11 @@ import (
// TwitterUser is the user data we receive from Twitter // TwitterUser is the user data we receive from Twitter
type TwitterUser struct { type TwitterUser struct {
ID string `json:"id_str"` ID string `json:"id_str"`
Email string `json:"email"` Email string `json:"email"`
Name string `json:"name"` Name string `json:"name"`
Description string `json:"description"`
ScreenName string `json:"screen_name"`
} }
// InstallTwitterAuth enables Twitter login for the app. // InstallTwitterAuth enables Twitter login for the app.
@ -93,6 +95,7 @@ func InstallTwitterAuth(app *aero.Application) {
defer response.Body.Close() defer response.Body.Close()
body, _ := ioutil.ReadAll(response.Body) body, _ := ioutil.ReadAll(response.Body)
fmt.Println(string(body))
// Construct a TwitterUser object // Construct a TwitterUser object
twUser := TwitterUser{} twUser := TwitterUser{}
@ -113,6 +116,7 @@ func InstallTwitterAuth(app *aero.Application) {
user.ConnectTwitter(twUser.ID) user.ConnectTwitter(twUser.ID)
// Save in DB // Save in DB
user.Accounts.Twitter.Nick = twUser.ScreenName
user.Save() user.Save()
// Log // Log
@ -145,6 +149,7 @@ func InstallTwitterAuth(app *aero.Application) {
// Add TwitterToUser reference // Add TwitterToUser reference
user.ConnectTwitter(twUser.ID) user.ConnectTwitter(twUser.ID)
user.Accounts.Twitter.Nick = twUser.ScreenName
user.LastLogin = arn.DateTimeUTC() user.LastLogin = arn.DateTimeUTC()
user.Save() user.Save()
@ -170,6 +175,10 @@ func InstallTwitterAuth(app *aero.Application) {
// Connect account to a Twitter account // Connect account to a Twitter account
user.ConnectTwitter(twUser.ID) user.ConnectTwitter(twUser.ID)
// Copy fields
user.Accounts.Twitter.Nick = twUser.ScreenName
user.Introduction = twUser.Description
// Save user object again with updated data // Save user object again with updated data
user.Save() user.Save()

View File

@ -51,16 +51,16 @@ component SettingsAccounts(user *arn.User)
Icon("circle-o") Icon("circle-o")
span Not connected span Not connected
//- .widget-section.social-account .widget-section.social-account
//- label(for="twitter") Twitter: label(for="twitter") Twitter:
//- a#twitter.button.social-account-button(href="/auth/twitter", data-ajax="false") a#twitter.button.social-account-button(href="/auth/twitter", data-ajax="false")
//- if user.Accounts.Twitter.ID != "" if user.Accounts.Twitter.ID != ""
//- Icon("check") Icon("check")
//- span Connected span Connected
//- else else
//- Icon("circle-o") Icon("circle-o")
//- span Not connected span Not connected
.widget.mountable .widget.mountable
h3.widget-title h3.widget-title