Welcome to mirror list, hosted at ThFree Co, Russian Federation.

login.html « html « web - github.com/MHSanaei/3x-ui.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2e03a4c595a2716fa2a19b8ec93a33c7fead64d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
{{ template "page/head_start" .}}
{{ template "page/head_end" .}}

{{ template "page/body_start" .}}
<a-layout id="app" v-cloak :class="themeSwitcher.currentTheme + ' login-app'">
  <transition name="list" appear>
    <a-layout-content class="under min-h-0">
      <div class="waves-header">
        <div class="waves-inner-header"></div>
        <svg class="waves" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
          viewBox="0 24 150 28" preserveAspectRatio="none" shape-rendering="auto">
          <defs>
            <path id="gentle-wave" d="M-160 44c30 0 58-18 88-18s 58 18 88 18 58-18 88-18 58 18 88 18 v44h-352z" />
          </defs>
          <g class="parallax">
            <use xlink:href="#gentle-wave" x="48" y="0" fill="rgba(0, 135, 113, 0.08)" />
            <use xlink:href="#gentle-wave" x="48" y="3" fill="rgba(0, 135, 113, 0.08)" />
            <use xlink:href="#gentle-wave" x="48" y="5" fill="rgba(0, 135, 113, 0.08)" />
            <use xlink:href="#gentle-wave" x="48" y="7" fill="#c7ebe2" />
          </g>
        </svg>
      </div>
      <a-row type="flex" justify="center" align="middle" class="h-100 overflow-y-auto overflow-x-hidden">
        <a-col :xs="22" :sm="12" :md="10" :lg="8" :xl="6" :xxl="5" id="login" class="my-3rem">
          <template v-if="!loadingStates.fetched">
            <div class="text-center">
              <a-spin size="large" />
            </div>
          </template>
          <template v-else>
            <div class="setting-section">
              <a-popover :overlay-class-name="themeSwitcher.currentTheme" title='{{ i18n "menu.settings" }}'
                placement="bottomRight" trigger="click">
                <template slot="content">
                  <a-space direction="vertical" :size="10">
                    <a-theme-switch-login></a-theme-switch-login>
                    <span>{{ i18n "pages.settings.language" }}</span>
                    <a-select ref="selectLang" class="w-100" v-model="lang" @change="LanguageManager.setLanguage(lang)"
                      :dropdown-class-name="themeSwitcher.currentTheme">
                      <a-select-option :value="l.value" label="English" v-for="l in LanguageManager.supportedLanguages">
                        <span role="img" aria-label="l.name" v-text="l.icon"></span>
                        &nbsp;&nbsp;<span v-text="l.name"></span>
                      </a-select-option>
                    </a-select>
                  </a-space>
                </template>
                <a-button shape="circle" icon="setting"></a-button>
              </a-popover>
            </div>
            <a-row type="flex" justify="center">
              <a-col :style="{ width: '100%' }">
                <h2 class="title headline zoom">
                  <span class="words-wrapper">
                    <b class="is-visible">{{ i18n "pages.login.hello" }}</b>
                    <b>{{ i18n "pages.login.title" }}</b>
                  </span>
                </h2>
              </a-col>
            </a-row>
            <a-row type="flex" justify="center">
              <a-col span="24">
                <a-form @submit.prevent="login">
                  <a-space direction="vertical" size="middle">
                    <a-form-item>
                      <a-input autocomplete="username" name="username" v-model.trim="user.username"
                        placeholder='{{ i18n "username" }}' autofocus required>
                        <a-icon slot="prefix" type="user" class="fs-1rem"></a-icon>
                      </a-input>
                    </a-form-item>
                    <a-form-item>
                      <a-input-password autocomplete="current-password" name="password" v-model.trim="user.password"
                        placeholder='{{ i18n "password" }}' required>
                        <a-icon slot="prefix" type="lock" class="fs-1rem"></a-icon>
                      </a-input-password>
                    </a-form-item>
                    <a-form-item v-if="twoFactorEnable">
                      <a-input autocomplete="one-time-code" name="twoFactorCode" v-model.trim="user.twoFactorCode"
                        placeholder='{{ i18n "twoFactorCode" }}' required>
                        <a-icon slot="prefix" type="key" class="fs-1rem"></a-icon>
                      </a-input>
                    </a-form-item>
                    <a-form-item>
                      <a-row justify="center" class="centered">
                        <div class="wave-btn-bg wave-btn-bg-cl h-50px mt-1rem"
                          :style="loadingStates.spinning ? 'width: 52px' : 'display: inline-block'">
                          <a-button class="ant-btn-primary-login" type="primary" :loading="loadingStates.spinning"
                            :icon="loadingStates.spinning ? 'poweroff' : undefined" html-type="submit">
                            [[ loadingStates.spinning ? '' : '{{ i18n "login" }}' ]]
                          </a-button>
                        </div>
                      </a-row>
                    </a-form-item>
                  </a-space>
                </a-form>
              </a-col>
            </a-row>
          </template>
        </a-col>
      </a-row>
    </a-layout-content>
  </transition>
</a-layout>
{{template "page/body_scripts" .}}
{{template "component/aThemeSwitch" .}}
<script>
  const app = new Vue({
    delimiters: ['[[', ']]'],
    el: '#app',
    data: {
      themeSwitcher,
      loadingStates: {
        fetched: false,
        spinning: false
      },
      user: {
        username: "",
        password: "",
        twoFactorCode: ""
      },
      twoFactorEnable: false,
      lang: "",
      animationStarted: false
    },
    async mounted() {
      this.lang = LanguageManager.getLanguage();
      this.twoFactorEnable = await this.getTwoFactorEnable();
    },
    methods: {
      async login() {
        this.loadingStates.spinning = true;
        const msg = await HttpUtil.post('/login', this.user);
        if (msg.success) {
          location.href = basePath + 'panel/';
        }
        this.loadingStates.spinning = false;
      },
      async getTwoFactorEnable() {
        const msg = await HttpUtil.post('/getTwoFactorEnable');
        if (msg.success) {
          this.twoFactorEnable = msg.obj;
          this.loadingStates.fetched = true;
          this.$nextTick(() => {
            if (!this.animationStarted) {
              this.animationStarted = true;
              this.initHeadline();
            }
          });
          return msg.obj;
        }
      },
      initHeadline() {
        const animationDelay = 2000;
        const rootEl = this.$el instanceof Element ? this.$el : document.getElementById('app');
        if (!rootEl || typeof rootEl.querySelectorAll !== 'function') {
          return;
        }
        const headlines = rootEl.querySelectorAll('.headline');
        headlines.forEach((headline) => {
          const first = headline.querySelector('.is-visible');
          if (!first) return;
          setTimeout(() => this.hideWord(first, animationDelay), animationDelay);
        });
      },
      hideWord(word, delay) {
        const nextWord = this.takeNext(word);
        this.switchWord(word, nextWord);
        setTimeout(() => this.hideWord(nextWord, delay), delay);
      },
      takeNext(word) {
        return word.nextElementSibling || word.parentElement.firstElementChild;
      },
      switchWord(oldWord, newWord) {
        oldWord.classList.remove('is-visible');
        oldWord.classList.add('is-hidden');
        newWord.classList.remove('is-hidden');
        newWord.classList.add('is-visible');
      }
    },
  });

  const pm_input_selector = 'input.ant-input, textarea.ant-input';
  const pm_strip_props = [
    'background',
    'background-color',
    'background-image',
    'color'
  ];

  const pm_observed_forms = new WeakSet();

  function pm_strip_inline(el) {
    if (!el || el.nodeType !== 1 || !el.matches?.(pm_input_selector)) return;

    let did_change = false;
    for (const prop of pm_strip_props) {
      if (el.style.getPropertyValue(prop)) {
        el.style.removeProperty(prop);
        did_change = true;
      }
    }

    if (did_change && el.style.length === 0) {
      el.removeAttribute('style');
    }
  }

  function pm_attach_observer(form) {
    if (pm_observed_forms.has(form)) return;
    pm_observed_forms.add(form);

    form.querySelectorAll(pm_input_selector).forEach(pm_strip_inline);

    const pm_mo = new MutationObserver(mutations => {
      for (const m of mutations) {
        if (m.type === 'attributes') {
          pm_strip_inline(m.target);
        } else if (m.type === 'childList') {
          for (const n of m.addedNodes) {
            if (n.nodeType !== 1) continue;
            if (n.matches?.(pm_input_selector)) pm_strip_inline(n);
            n.querySelectorAll?.(pm_input_selector).forEach(pm_strip_inline);
          }
        }
      }
    });

    pm_mo.observe(form, {
      attributes: true,
      attributeFilter: ['style'],
      childList: true,
      subtree: true
    });
  }

  function pm_init() {
    document.querySelectorAll('form.ant-form').forEach(pm_attach_observer);
    const pm_host = document.getElementById('login') || document.body;
    const pm_wait_for_forms = new MutationObserver(mutations => {
      for (const m of mutations) {
        for (const n of m.addedNodes) {
          if (n.nodeType !== 1) continue;
          if (n.matches?.('form.ant-form')) pm_attach_observer(n);
          n.querySelectorAll?.('form.ant-form').forEach(pm_attach_observer);
        }
      }
    });
    pm_wait_for_forms.observe(pm_host, {
      childList: true,
      subtree: true
    });
  }

  if (document.readyState === 'loading') {
    document.addEventListener('DOMContentLoaded', pm_init, {
      once: true
    });
  } else {
    pm_init();
  }
</script>
{{ template "page/body_end" .}}