|
6 | 6 | {{ form.as_p }}
|
7 | 7 | <button type="submit">Sign Up</button>
|
8 | 8 | </form>
|
| 9 | + <button onclick="signup2()">Sigup with scatter</button> |
9 | 10 | </div>
|
10 | 11 | {% endblock content %}
|
11 | 12 | {% block javascript %}
|
|
27 | 28 | chainId: CHAIN_ID
|
28 | 29 | };
|
29 | 30 | */
|
30 |
| - var signup = '{% url 'scatterauth_signup_api' %}'; |
31 |
| - var fields = ['email']; |
32 |
| - var public_key_field_name = 'username'; |
| 31 | + function signup2() { |
| 32 | + const network = ScatterJS.Network.fromJson({ |
| 33 | + blockchain: 'eos', |
| 34 | + chainId: 'e70aaab8997e1dfce58fbfac80cbbb8fecec7b99cf982a9444273cbc64c41473', |
| 35 | + host: 'jungle2.cryptolions.io', |
| 36 | + port: 80, |
| 37 | + protocol: 'http' |
| 38 | + }); |
| 39 | + |
| 40 | + const signup_url = '{% url 'scatterauth_signup_api' %}'; |
| 41 | + const fields = []; |
| 42 | + const public_key_field_name = 'username'; |
| 43 | + |
| 44 | + ScatterJS.connect('baf', network).then( |
| 45 | + connected => { |
| 46 | + if (connected) { |
| 47 | + let scatter = ScatterJS.scatter; |
| 48 | + console.log("Scatter installed!"); |
| 49 | + console.log(scatter.identity) |
| 50 | + if (scatter.identity) { |
| 51 | + // login the user with api |
| 52 | + console.log("Identity found"); |
| 53 | + console.log(scatter.identity); |
| 54 | + console.log("Welcome, " + scatter.identity.name + '<br>Your public key: ' + scatter.identity.publicKey); |
| 55 | + signupWithData( |
| 56 | + scatter.identity.publicKey, |
| 57 | + public_key_field_name, |
| 58 | + null, |
| 59 | + signup_url, |
| 60 | + x=>console.log(x), |
| 61 | + response => {document.location = response.redirect_url}, |
| 62 | + response => alert(JSON.stringify(response.error)) |
| 63 | + ) |
| 64 | + } else { |
| 65 | + requestIdentity( |
| 66 | + fields, |
| 67 | + public_key_field_name, |
| 68 | + signup_url, |
| 69 | + network, |
| 70 | + console.log |
| 71 | + ) |
| 72 | + } |
| 73 | + console.log(x); |
| 74 | + if(x.success){ |
| 75 | + document.location = result.redirect_url; |
| 76 | + } else { |
| 77 | + alert(x.error); |
| 78 | + } |
| 79 | + } |
| 80 | + else { |
| 81 | + alert('not connected'); |
| 82 | + } |
| 83 | + } |
| 84 | + ); |
| 85 | + } |
33 | 86 |
|
34 |
| - document.addEventListener('scatterLoaded', scatterExtension => { |
35 |
| - console.log("Scatter installed!"); |
36 |
| - if (scatter.identity) { |
37 |
| - // login the user with api |
38 |
| - console.log("Identity found"); |
39 |
| - console.log(scatter.identity); |
40 |
| - console.log("Welcome, " + scatter.identity.name + '<br>Your public key: ' + scatter.identity.publicKey); |
41 |
| - } else { |
42 |
| - requestIdentity(fields,public_key_field_name, signup, null, console.log); |
43 |
| - } |
44 |
| - }); |
45 | 87 | </script>
|
46 | 88 | {% endblock javascript %}
|
0 commit comments