123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- // 帳號登入
- $("#btn_login").click(function() {
- var username = $('#username').val();
- var password = $('#password').val();
- var param_string = {
- username: username,
- password: password
- };
- if (username == '' || password == '') {
- return;
- }
- $.ajax({
- type: 'POST',
- url: 'https://api.ptt.cx:8750/api/v1/login/access-token',
- data: param_string,
- success: function(res, textStatus, jqXHR) {
- console.log(res); // test
- // 將access_token寫入localStorage
- // {access_token: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjE2N…kyIn0.wwRK7OKPICdbcOhLfgqA5u5uxkhRVP2gQeqEF8tCY4g', token_type: 'bearer'}
- var access_token = res.access_token;
- if (access_token != null) {
- // 導頁進Dashboard介面
- Swal.fire({
- title: '登入成功',
- icon: 'success',
- confirmButtonColor: '#3085d6'
- });
- window.setTimeout(() => {
- window.location.href = 'index.html';
- }, 1500);
- }
- }, error: function(xhr, status, error) {
- console.log(xhr.responseText); // test
- var res = JSON.parse(xhr.responseText);
-
- if (res.detail == 'Incorrect email or password') {
- Swal.fire({
- title: '注意',
- icon: 'error',
- text: '帳號/密碼錯誤,請重新輸入',
- confirmButtonColor: '#3085d6'
- });
- }
- }
- });
- return false;
- });
|