@zzish/sdk-js 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/user.html ADDED
@@ -0,0 +1,139 @@
1
+ <!doctype html>
2
+
3
+ <html lang="en">
4
+ <head>
5
+ <meta charset="utf-8">
6
+
7
+ <title>Zzish Quick Javascript Client SDK</title>
8
+
9
+ <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
10
+ <script src="https://code.jquery.com/jquery-1.11.2.min.js"></script>
11
+
12
+ <script src="zzish.js"></script>
13
+ <script>
14
+ var profileId;
15
+ var init = false;
16
+ var token = null;
17
+
18
+ $(document).ready(function() {
19
+ logoutUser();
20
+ });
21
+
22
+ function logoutUser() {
23
+ profileId = "";
24
+ $("#profileIdSpan").html("You need to login");
25
+ $("#profileNameSpan").html("You need to login");
26
+ token = null;
27
+ $("#loginButtons").show();
28
+ $("#logoutButtons").hide();
29
+ }
30
+
31
+ function loginUser(data) {
32
+ profileId = data.id;
33
+ $("#profileIdSpan").html(profileId);
34
+ $("#profileNameSpan").html(data.name);
35
+ token = data.token;
36
+ $("#loginButtons").hide();
37
+ $("#logoutButtons").show();
38
+ }
39
+
40
+ function initApp() {
41
+ if (!init) {
42
+ if ($("#appId").val()!="") {
43
+ Zzish.init({
44
+ api: $("#appId").val(),
45
+ protocol: "http",
46
+ baseUrl: "localhost:8080/zzishapi/api/",
47
+ webUrl: "http://localhost:3000/",
48
+ header: "X-ApplicationId",
49
+ headerprefix: "",
50
+ logEnabled: true
51
+ });
52
+ init = true;
53
+ console.log("App Initalized with id",$("#appId").val());
54
+ Zzish.getCurrentUser(null,function(err,data) {
55
+ if (data!=null) {
56
+ //we have a token
57
+ loginUser(data);
58
+ }
59
+ })
60
+ }
61
+ else {
62
+ alert ("Please enter your API KEY from http://www.zzish.co.uk/developer/")
63
+ }
64
+ }
65
+ return init;
66
+ }
67
+
68
+ function loginPop() {
69
+ if (initApp()) {
70
+ loginCommand("pop","success.html");
71
+ }
72
+ }
73
+
74
+ function loginRedirect() {
75
+ if (initApp()) {
76
+ loginCommand("redirect","redirect.html")
77
+ }
78
+ }
79
+
80
+ function loginCommand(type,redirectURL) {
81
+ if (profileId=="") {
82
+ Zzish.login(type,"http://zzish.github.io/zzishsdk-js/"+redirectURL,function(err,message) {
83
+ console.log("Logged in with status and message",err,message);
84
+ if (!err) {
85
+ loginUser(message);
86
+ }
87
+ else {
88
+ console.log("Error",err);
89
+ }
90
+ });
91
+ }
92
+ }
93
+
94
+ function logout() {
95
+ if (initApp()) {
96
+ if (token!="" && token!="undefined" && profileId!="") {
97
+ Zzish.logout(token,function(err,message) {
98
+ console.log("Logged in with status and message",err,message);
99
+ if (!err) {
100
+ logoutUser();
101
+ }
102
+ });
103
+ }
104
+ }
105
+ }
106
+
107
+ function groups() {
108
+ if (initApp()) {
109
+ if (token!="" && token!="undefined" && profileId!="") {
110
+ Zzish.listGroups(profileId,function(err,message) {
111
+ console.log("Got groups",err,message);
112
+ if (!err) {
113
+ $("#groupOutput").html(JSON.stringify(message));
114
+ }
115
+ });
116
+ }
117
+ }
118
+ }
119
+
120
+
121
+ </script>
122
+ </head>
123
+
124
+ <body>
125
+ <input type="text" id="appId" name="appId" placeholder="Your API Key" value="" size="40"/><br/>
126
+ <h1>Login</h1>
127
+ <div id="loginButtons">
128
+ <input type="button" onclick="loginPop()" value="Login with Popup"/><br/>
129
+ <input type="button" onclick="loginRedirect()" value="Login with Redirect"/><br/>
130
+ </div>
131
+ <div id="logoutButtons">
132
+ <input type="button" onclick="groups()" value="List Groups"/><br/>
133
+ <input type="button" onclick="logout()" value="Logout"/><br/>
134
+ Group Output: <span id="groupOutput"></span>
135
+ </div>
136
+ Profile Id: <span id="profileIdSpan">You need to login to get a profile Id</span><br/>
137
+ Profile Name: <span id="profileNameSpan">You need to login to get a profile Name</span><br/>
138
+ </body>
139
+ </html>