github.com/aarzilli/tools@v0.0.0-20151123112009-0d27094f75e0/appengine/login/gitkit/tpl_html_content.go (about) 1 package gitkit 2 3 import ( 4 "fmt" 5 6 "github.com/pbberlin/tools/net/http/routes" 7 ) 8 9 // client side javascript to measure signin status 10 const signedInCode = ` 11 <script type=text/javascript> 12 function getCookie(name) { 13 name = name + "="; 14 var ca = document.cookie.split(';'); 15 for(var i=0; i<ca.length; i++) { 16 var c = ca[i]; 17 while (c.charAt(0)==' ') c = c.substring(1); 18 if (c.indexOf(name) == 0) return name + " is present"; 19 } 20 return ""; 21 } 22 console.log( "cukis:", getCookie("gtoken") ); 23 </script> 24 ` 25 26 const home1 = `{{if not .User}} 27 <!-- 28 We could just as easy do automatic forwarding if not signed on: 29 30 <script type=text/javascript> 31 google.identitytoolkit.setConfig({ 32 widgetUrl: '{{.WidgetURL}}' 33 }); 34 // automatic forwarding to login: 35 // google.identitytoolkit.signIn(); 36 </script> 37 <a href="#" onclick="google.identitytoolkit.signIn()">Sign In</a><br><br> 38 39 --> 40 41 42 <div id="navbar"></div> 43 <script type=text/javascript> 44 google.identitytoolkit.signInButton( 45 '#navbar', 46 { 47 widgetUrl: '{{.WidgetURL}}', 48 signOutUrl: '{{.SignOutURL}}' 49 } 50 ); 51 </script> 52 53 54 55 56 {{else}} 57 58 <div id="navbar"></div> 59 <script type=text/javascript> 60 google.identitytoolkit.signInButton( 61 '#navbar', 62 { 63 widgetUrl: '{{.WidgetURL}}', 64 signOutUrl: '{{.SignOutURL}}' 65 } 66 ); 67 </script> 68 69 <br> 70 <p>Hello {{.User.Name}} ID: {{.User.ID}} Email: {{.User.Email}}</p> 71 <p> 72 14119357422359180555 - peter.buchmann@web.de<br> 73 14952300052240127534 - peter.buchmann.68@gmail.com<br> 74 </p> 75 76 <p><a href="https://security.google.com/settings/security/permissions">Remove Google App Permissions</a></p> 77 <p><a href="https://www.facebook.com/settings?tab=applications">Remove Facebook App Permissions</a></p> 78 79 {{ .CookieDump }} 80 81 {{end}}` 82 83 const home2 = `{{if .User}} 84 <p>Your favorite weekday:</p> 85 <form method="POST" action="{{.UpdateWeekdayURL}}"> 86 <input type="hidden" name="xsrftoken" value="{{.UpdateWeekdayXSRFToken}}"> 87 <select name="favorite"> 88 {{range $index, $weekday := .Weekdays}} 89 <option value="{{$index}}" {{if eq $.WeekdayIndex $index}}selected{{end}}>{{$weekday}}</option>{{end}} 90 </select> 91 <button type="submit">change</button> 92 </form> 93 {{end}}` 94 95 const widget = fmt.Sprintf(`<div id="gitkitWidget"></div> 96 <script type="text/javascript"> 97 98 99 var brandingURL = "https://%v.appspot.com/auth/accountChooserBranding.html"; 100 var faviconURL = "https://%v.appspot.com/favicon.ico"; 101 var accountChooserConfig = { 102 title: 'Sign in to tec-news', 103 favicon: faviconURL, 104 branding: brandingURL, 105 }; 106 107 if (window.location.hostname == "localhost") { 108 faviconURL = ""; 109 brandingURL = ""; 110 accountChooserConfig = {}; 111 } 112 113 114 google.identitytoolkit.start( 115 '#gitkitWidget', 116 { 117 apiKey: '{{.BrowserAPIKey}}', 118 signInSuccessUrl: '{{.SignInSuccessUrl}}', 119 signOutUrl: '{{.SignOutURL}}', 120 oobActionUrl: '{{.OOBActionURL}}', 121 signInOptions: ['google','facebook'], 122 siteName: 'tec-news', 123 acUiConfig: accountChooserConfig, 124 }, 125 126 127 '{{.POSTBody}}'); 128 // acUiConfig - 129 // is rejected because of "invalid domain" 130 // favicon: 'http://tec-news.appspot.com/favicon.ico' 131 // favicon: 'http://localhost:8087/favicon.ico' 132 // branding: 'http://tec-news.appspot.com/account_choooser_branding' 133 134 // "signInOptions": ["password","google","facebook"] 135 136 // siteName required for "manage account" 137 </script> 138 `, routes.AppID(), routes.AppID())