userModel.js 1.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. function UserModel(_lineUserId) {
  2. let m_lineUserId = _lineUserId;
  3. function init() {
  4. }
  5. /**
  6. * 用戶登入
  7. * @returns {TypeUserResponse} Promise
  8. */
  9. function loginUser () {
  10. return GET('/api/survey/healthyPassPort/profile?lineUserId='+m_lineUserId);
  11. }
  12. /**
  13. * 用戶註冊
  14. * @param {object} _formdata
  15. * @returns {TypeResponse} Promise
  16. */
  17. function registerUser (_formdata) {
  18. return POST('/api/survey/healthyPassPort/post', {
  19. lineUserId: m_lineUserId,
  20. ..._formdata,
  21. }).catch((error)=> {
  22. console.log('_register:' + error);
  23. throw '表單儲存失敗';
  24. });
  25. }
  26. /**
  27. * 用戶更新頭貼
  28. * @returns {TypeUserResponse} Promise
  29. */
  30. function updatePhoto(base64Image) {
  31. return POST('/api/survey/healthyPassPort/stickerUpdate', {
  32. lineUserId: m_lineUserId,
  33. headSticker: base64Image,
  34. });
  35. }
  36. /**
  37. * 驗證表單
  38. * @param {object} formdata
  39. * @returns {Object | boolean}
  40. */
  41. function verifyUserForm(theContext) {
  42. const {userName, IDNo, phone, birthday} = formdata;
  43. let output;
  44. if (!userName || userName.length === 0) {
  45. output['userName'] = '姓名格式不正確';
  46. }
  47. if (/[A-Za-z]{1}[1-2]{1}[0-9]{8}$/.test(IDNo)) {
  48. output['IDNo'] = '身分證格式不正確';
  49. }
  50. if (/09\d{2}\d{3}\d{3}/.test(phone)) {
  51. output['phone'] = '電話格式不正確';
  52. }
  53. if (!/[0-9]{4}\/[0-9]{3}\/[0-9]{3}$/.test(birthday)) {
  54. output['birthday'] = '生日格式不正確';
  55. }
  56. if (output) {
  57. return output;
  58. }
  59. return true;
  60. }
  61. {
  62. init();
  63. }
  64. return {
  65. loginUser,
  66. registerUser,
  67. verifyUserForm,
  68. updatePhoto
  69. }
  70. }