MCPcopy Create free account
hub / github.com/MALSync/MALSync / authentication

Method authentication

src/kitsu/kitsuClass.ts:100–180  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

98 }
99
100 authentication() {
101 try {
102 utils.checkDoubleExecution();
103 } catch (e) {
104 con.error(e);
105 }
106 $(document).ready(function () {
107 $('body').after(
108 j.html(
109 `
110 <div id="mal-sync-login" style="text-align: center; margin-top: 50px; background-color: white; border: 1px solid lightgrey; padding: 10px; max-width: 600px; margin-left: auto; margin-right: auto;">
111 <h1>MAL-Sync</h1>
112 <br>
113 <p style="text-align: left;">
114 ${api.storage.lang('kitsuClass_authentication_text')}
115 </p>
116 <div class="modal-content">
117 <input type="email" id="email" placeholder="Email" required>
118 <input type="password" id="pass" name="password" placeholder="${api.storage.lang(
119 'kitsuClass_authentication_Password',
120 )}" required>
121 </div>
122 <div class="form-cta" style="margin-top: 30px;">
123 <button class="btn button--primary" type="submit" id="mal-sync-button">
124 ${api.storage.lang('kitsuClass_authentication_Login')}
125 </button>
126 </div>
127 </div>
128 `,
129 ),
130 );
131 $('#mal-sync-login #mal-sync-button').click(function () {
132 $('#mal-sync-login #mal-sync-button').attr('disabled', 'disabled');
133 $.ajax({
134 type: 'POST',
135 url: 'https://kitsu.app/api/oauth/token',
136 data: `grant_type=password&username=${encodeURIComponent(
137 String($('#mal-sync-login #email').val()),
138 )}&password=${encodeURIComponent(String($('#mal-sync-login #pass').val()))}`,
139 async success(result) {
140 const token = result.access_token;
141
142 if (!token) return;
143
144 con.info('token', token);
145
146 await api.settings.set('kitsuToken', token);
147
148 $('#mal-sync-login').html(
149 j.html(
150 `<h1>MAL-Sync</h1><br>${api.storage.lang('kitsuClass_authentication_Success')}`,
151 ),
152 );
153 },
154 error(result) {
155 try {
156 con.error(result);
157 $('#mal-sync-login #mal-sync-button').prop('disabled', false);

Callers 1

initMethod · 0.95

Calls 3

errorMethod · 0.80
langMethod · 0.80
removeMethod · 0.80

Tested by

no test coverage detected