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

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

View File

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