login.html 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311
  1. <!doctype html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover">
  6. <title>CocoBuddy</title>
  7. <style>
  8. :root {
  9. --bg: #f6f7fb;
  10. --card: #ffffff;
  11. --ink: #171a20;
  12. --muted: #6b7280;
  13. --line: #e6e8ef;
  14. --brand: #2f6bff;
  15. --brand-ink: #ffffff;
  16. --danger: #c0392b;
  17. --radius: 14px;
  18. }
  19. * { box-sizing: border-box; }
  20. html, body { height: 100%; margin: 0; }
  21. body {
  22. background: radial-gradient(1200px 600px at 50% -10%, #e8efff 0%, var(--bg) 55%);
  23. color: var(--ink);
  24. font: 15px/1.6 -apple-system, "Segoe UI", system-ui, "PingFang SC", "Microsoft YaHei", sans-serif;
  25. display: flex; align-items: center; justify-content: center;
  26. padding: 24px;
  27. }
  28. .card {
  29. width: 100%; max-width: 420px; background: var(--card);
  30. border: 1px solid var(--line); border-radius: 20px; padding: 32px 28px 26px;
  31. box-shadow: 0 24px 60px rgba(23, 26, 32, .08);
  32. }
  33. .logo { display: flex; align-items: center; gap: 10px; margin-bottom: 22px; }
  34. .mark {
  35. width: 34px; height: 34px; border-radius: 10px;
  36. background: linear-gradient(135deg, #2f6bff, #7ab0ff);
  37. color: #fff; font-weight: 700; display: flex; align-items: center; justify-content: center;
  38. font-size: 17px;
  39. }
  40. .logo b { font-size: 16px; letter-spacing: .2px; }
  41. .logo span { color: var(--muted); font-size: 12px; }
  42. h1 { font-size: 20px; margin: 0 0 6px; letter-spacing: -.2px; }
  43. .sub { color: var(--muted); font-size: 13px; margin: 0 0 22px; }
  44. label { display: block; font-size: 12.5px; color: var(--muted); margin: 0 0 6px; }
  45. input, select {
  46. width: 100%; height: 42px; padding: 0 12px; border: 1px solid var(--line);
  47. border-radius: 10px; background: #fff; color: var(--ink); font-size: 14.5px;
  48. outline: none; transition: border-color .15s, box-shadow .15s;
  49. }
  50. input:focus, select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(47, 107, 255, .12); }
  51. .field { margin-bottom: 14px; }
  52. .row { display: flex; gap: 10px; }
  53. .row > * { flex: 1; }
  54. button {
  55. width: 100%; height: 44px; border: 0; border-radius: 11px; background: var(--brand);
  56. color: var(--brand-ink); font-size: 15px; font-weight: 600; cursor: pointer;
  57. margin-top: 6px; transition: filter .15s, transform .05s;
  58. }
  59. button:hover { filter: brightness(1.04); }
  60. button:active { transform: translateY(1px); }
  61. button[disabled] { opacity: .6; cursor: default; }
  62. .tabs { display: flex; gap: 18px; border-bottom: 1px solid var(--line); margin-bottom: 18px; }
  63. .tab {
  64. padding: 0 0 10px; font-size: 13.5px; color: var(--muted); cursor: pointer;
  65. border-bottom: 2px solid transparent; margin-bottom: -1px; background: none; width: auto;
  66. height: auto; border-radius: 0; font-weight: 500;
  67. }
  68. .tab.on { color: var(--ink); border-bottom-color: var(--brand); font-weight: 600; }
  69. .or {
  70. display: flex; align-items: center; gap: 10px;
  71. color: var(--muted); font-size: 12px; margin: 16px 0 4px;
  72. }
  73. .or::before, .or::after { content: ''; flex: 1; height: 1px; background: var(--line); }
  74. .hint { font-size: 12px; color: var(--muted); margin-top: 12px; }
  75. .err {
  76. margin-top: 14px; padding: 10px 12px; border-radius: 10px; font-size: 13px;
  77. background: #fdf1ef; color: var(--danger); border: 1px solid #f4d4cf; display: none;
  78. word-break: break-word;
  79. }
  80. .err.on { display: block; }
  81. .foot { margin-top: 18px; text-align: center; font-size: 12px; color: #9aa1ad; }
  82. [hidden] { display: none !important; }
  83. @media (max-width: 480px) {
  84. .card { padding: 26px 20px 22px; border-radius: 16px; }
  85. body { padding: 12px; }
  86. }
  87. </style>
  88. </head>
  89. <body>
  90. <form class="card" id="form" autocomplete="on">
  91. <div class="logo">
  92. <div class="mark">C</div>
  93. <div>
  94. <b>CocoBuddy</b><br>
  95. <span id="tagline">教学与办公助手 · Web 版</span>
  96. </div>
  97. </div>
  98. <h1 id="title">登录</h1>
  99. <p class="sub" id="subtitle">用你的可可课堂账号登录,和桌面客户端是同一个账号。</p>
  100. <div id="ssoPane" hidden>
  101. <button type="button" id="sso">用可可课堂账号登录</button>
  102. <div class="or"><span id="orText">或</span></div>
  103. </div>
  104. <div class="field">
  105. <label id="regionLabel">区域</label>
  106. <select id="region">
  107. <option value="zh-CN">中国内地 · cocorobo.cn</option>
  108. <option value="zh-HK">中国香港 · cocorobo.hk</option>
  109. <option value="en">International · cocorobo.com</option>
  110. </select>
  111. </div>
  112. <div class="tabs">
  113. <button type="button" class="tab on" data-mode="password" id="tabPassword">账号密码</button>
  114. <button type="button" class="tab" data-mode="key" id="tabKey">API Key</button>
  115. </div>
  116. <div id="passwordPane">
  117. <div class="field">
  118. <label id="accountLabel">账号 / 手机号</label>
  119. <input id="account" name="username" autocomplete="username" spellcheck="false">
  120. </div>
  121. <div class="field">
  122. <label id="passwordLabel">密码</label>
  123. <input id="password" name="password" type="password" autocomplete="current-password">
  124. </div>
  125. </div>
  126. <div id="keyPane" hidden>
  127. <div class="field">
  128. <label id="keyLabel">API Key</label>
  129. <input id="apiKey" spellcheck="false" autocomplete="off">
  130. </div>
  131. <p class="hint" id="keyHint">在桌面客户端「设置 → 账号」里可以看到,或让管理员给你一份。</p>
  132. </div>
  133. <button type="submit" id="submit">登录</button>
  134. <div class="err" id="err"></div>
  135. <div class="foot" id="foot">登录后会在服务器上为你准备一份独立的工作环境</div>
  136. </form>
  137. <script>
  138. window.__CC_SSO__ = __CC_SSO_JSON__
  139. (function () {
  140. var I18N = {
  141. 'zh-CN': {
  142. tagline: '教学与办公助手 · Web 版',
  143. title: '登录',
  144. subtitle: '用你的可可课堂账号登录,和桌面客户端是同一个账号。',
  145. region: '区域',
  146. account: '账号 / 手机号',
  147. password: '密码',
  148. key: 'API Key',
  149. keyHint: '在桌面客户端「设置 → 账号」里可以看到,或让管理员给你一份。',
  150. username: '账号密码',
  151. submit: '登录',
  152. working: '正在登录…',
  153. sso: '用可可课堂账号登录',
  154. or: '或',
  155. foot: '登录后会在服务器上为你准备一份独立的工作环境',
  156. empty: '请填写账号和密码',
  157. emptyKey: '请填写 API Key'
  158. },
  159. 'zh-HK': {
  160. tagline: '教學與辦公助手 · Web 版',
  161. title: '登入',
  162. subtitle: '用你的 cococlass 帳號登入,和桌面客戶端是同一個帳號。',
  163. region: '區域',
  164. account: '帳號 / 手機號',
  165. password: '密碼',
  166. key: 'API Key',
  167. keyHint: '在桌面客戶端「設定 → 帳號」裡可以看到,或讓管理員給你一份。',
  168. username: '帳號密碼',
  169. submit: '登入',
  170. working: '正在登入…',
  171. sso: '用可可課堂帳號登入',
  172. or: '或',
  173. foot: '登入後會在伺服器上為你準備一份獨立的工作環境',
  174. empty: '請填寫帳號和密碼',
  175. emptyKey: '請填寫 API Key'
  176. },
  177. en: {
  178. tagline: 'Teaching & office assistant · Web',
  179. title: 'Sign in',
  180. subtitle: 'Use your cococlass account — same account as the desktop client.',
  181. region: 'Region',
  182. account: 'Account / phone',
  183. password: 'Password',
  184. key: 'API Key',
  185. keyHint: 'Find it in the desktop client under Settings → Account, or ask your admin.',
  186. username: 'Password',
  187. submit: 'Sign in',
  188. working: 'Signing in…',
  189. sso: 'Sign in with CocoClass account',
  190. or: 'or',
  191. foot: 'A private workspace will be prepared for you on the server',
  192. empty: 'Enter your account and password',
  193. emptyKey: 'Enter your API Key'
  194. }
  195. }
  196. var nav = String(navigator.language || 'zh-CN').toLowerCase().replace(/_/g, '-')
  197. var locale = nav.indexOf('en') === 0 ? 'en' : (/hant|tw|hk|mo/.test(nav) ? 'zh-HK' : 'zh-CN')
  198. var t = I18N[locale]
  199. var mode = 'password'
  200. function $(id) { return document.getElementById(id) }
  201. function apply () {
  202. $('tagline').textContent = t.tagline
  203. $('title').textContent = t.title
  204. $('subtitle').textContent = t.subtitle
  205. $('regionLabel').textContent = t.region
  206. $('accountLabel').textContent = t.account
  207. $('passwordLabel').textContent = t.password
  208. $('keyLabel').textContent = t.key
  209. $('keyHint').textContent = t.keyHint
  210. $('tabPassword').textContent = t.username
  211. $('submit').textContent = t.submit
  212. $('foot').textContent = t.foot
  213. document.documentElement.lang = locale
  214. }
  215. apply()
  216. $('region').value = locale
  217. // 配了平台单点登录:主按钮直接去平台自己的登录界面(服务端补 state 与 redirect)。
  218. // 表单保留,API Key 仍可用于自测或管理员发 key。
  219. var boot = window.__CC_SSO__ || {}
  220. var sso = boot.sso
  221. if (sso && sso.url) {
  222. $('ssoPane').hidden = false
  223. $('sso').textContent = t.sso || '用可可课堂账号登录'
  224. $('orText').textContent = t.or || '或'
  225. $('sso').addEventListener('click', function () {
  226. location.href = '/_cc/login?sso=1'
  227. })
  228. }
  229. Array.prototype.forEach.call(document.querySelectorAll('.tab'), function (tab) {
  230. tab.addEventListener('click', function () {
  231. mode = tab.getAttribute('data-mode')
  232. Array.prototype.forEach.call(document.querySelectorAll('.tab'), function (x) {
  233. x.classList.toggle('on', x === tab)
  234. })
  235. $('passwordPane').hidden = mode !== 'password'
  236. $('keyPane').hidden = mode !== 'key'
  237. })
  238. })
  239. function fail (message) {
  240. var box = $('err')
  241. box.textContent = message
  242. box.classList.add('on')
  243. }
  244. function deviceId () {
  245. try {
  246. var saved = localStorage.getItem('cc.device')
  247. if (saved) return saved
  248. var made = 'web-' + Math.random().toString(36).slice(2) + Date.now().toString(36)
  249. localStorage.setItem('cc.device', made)
  250. return made
  251. } catch (err) { return '' }
  252. }
  253. // 单点登录回调失败会带 ?err= 回来,直接显示原因
  254. var query = new URLSearchParams(location.search)
  255. if (query.get('err')) fail(query.get('err'))
  256. $('form').addEventListener('submit', async function (event) {
  257. event.preventDefault()
  258. $('err').classList.remove('on')
  259. var region = $('region').value
  260. var body = { region: region, locale: region, deviceId: deviceId() }
  261. if (mode === 'key') {
  262. var key = $('apiKey').value.trim()
  263. if (!key) return fail(t.emptyKey)
  264. body.apiKey = key
  265. } else {
  266. var account = $('account').value.trim()
  267. var password = $('password').value
  268. if (!account || !password) return fail(t.empty)
  269. body.mode = 'password'
  270. body.account = account
  271. body.password = password
  272. }
  273. $('submit').disabled = true
  274. $('submit').textContent = t.working
  275. try {
  276. var res = await fetch('/_cc/api/login', {
  277. method: 'POST',
  278. headers: { 'content-type': 'application/json' },
  279. body: JSON.stringify(body)
  280. })
  281. var json = await res.json().catch(function () { return null })
  282. if (!res.ok || !json || !json.ok) {
  283. throw new Error((json && json.error) || ('HTTP ' + res.status))
  284. }
  285. location.replace('/')
  286. } catch (err) {
  287. fail(err.message || 'sign-in failed')
  288. $('submit').disabled = false
  289. $('submit').textContent = t.submit
  290. }
  291. })
  292. })()
  293. </script>
  294. </body>
  295. </html>