admin.js 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738
  1. module.exports = function(crowi, app) {
  2. 'use strict';
  3. var debug = require('debug')('crowi:routes:admin')
  4. , models = crowi.models
  5. , Page = models.Page
  6. , User = models.User
  7. , ExternalAccount = models.ExternalAccount
  8. , UserGroup = models.UserGroup
  9. , Config = models.Config
  10. , PluginUtils = require('../plugins/plugin-utils')
  11. , pluginUtils = new PluginUtils()
  12. , ApiResponse = require('../util/apiResponse')
  13. , MAX_PAGE_LIST = 5
  14. , actions = {};
  15. function createPager(total, limit, page, pagesCount, maxPageList) {
  16. const pager = {
  17. page: page,
  18. pagesCount: pagesCount,
  19. pages: [],
  20. total: total,
  21. previous: null,
  22. previousDots: false,
  23. next: null,
  24. nextDots: false,
  25. };
  26. if (page > 1) {
  27. pager.previous = page - 1;
  28. }
  29. if (page < pagesCount) {
  30. pager.next = page + 1;
  31. }
  32. let pagerMin = Math.max(1, Math.ceil(page - maxPageList/2));
  33. let pagerMax = Math.min(pagesCount, Math.floor(page + maxPageList/2));
  34. if (pagerMin === 1) {
  35. if (MAX_PAGE_LIST < pagesCount) {
  36. pagerMax = MAX_PAGE_LIST;
  37. } else {
  38. pagerMax = pagesCount;
  39. }
  40. }
  41. if (pagerMax === pagesCount) {
  42. if ((pagerMax - MAX_PAGE_LIST) < 1) {
  43. pagerMin = 1;
  44. } else {
  45. pagerMin = pagerMax - MAX_PAGE_LIST;
  46. }
  47. }
  48. pager.previousDots = null;
  49. if (pagerMin > 1) {
  50. pager.previousDots = true;
  51. }
  52. pager.nextDots = null;
  53. if (pagerMax < pagesCount) {
  54. pager.nextDots = true;
  55. }
  56. for (let i = pagerMin; i <= pagerMax; i++) {
  57. pager.pages.push(i);
  58. }
  59. return pager;
  60. }
  61. actions.index = function(req, res) {
  62. return res.render('admin/index', {
  63. plugins: pluginUtils.listPlugins(crowi.rootDir),
  64. });
  65. };
  66. // app.get('/admin/app' , admin.app.index);
  67. actions.app = {};
  68. actions.app.index = function(req, res) {
  69. var settingForm;
  70. settingForm = Config.setupCofigFormData('crowi', req.config);
  71. return res.render('admin/app', {
  72. settingForm: settingForm,
  73. });
  74. };
  75. actions.app.settingUpdate = function(req, res) {
  76. };
  77. // app.get('/admin/security' , admin.security.index);
  78. actions.security = {};
  79. actions.security.index = function(req, res) {
  80. var settingForm;
  81. settingForm = Config.setupCofigFormData('crowi', req.config);
  82. return res.render('admin/security', { settingForm });
  83. };
  84. // app.get('/admin/markdown' , admin.markdown.index);
  85. actions.markdown = {};
  86. actions.markdown.index = function(req, res) {
  87. var config = crowi.getConfig();
  88. var markdownSetting = Config.setupCofigFormData('markdown', config);
  89. return res.render('admin/markdown', {
  90. markdownSetting: markdownSetting,
  91. });
  92. };
  93. // app.post('/admin/markdown/lineBreaksSetting' , admin.markdown.lineBreaksSetting);
  94. actions.markdown.lineBreaksSetting = function(req, res) {
  95. var markdownSetting = req.form.markdownSetting;
  96. req.session.markdownSetting = markdownSetting;
  97. if (req.form.isValid) {
  98. Config.updateNamespaceByArray('markdown', markdownSetting, function(err, config) {
  99. Config.updateConfigCache('markdown', config);
  100. req.session.markdownSetting = null;
  101. req.flash('successMessage', ['Successfully updated!']);
  102. return res.redirect('/admin/markdown');
  103. });
  104. } else {
  105. req.flash('errorMessage', req.form.errors);
  106. return res.redirect('/admin/markdown');
  107. }
  108. };
  109. // app.get('/admin/customize' , admin.customize.index);
  110. actions.customize = {};
  111. actions.customize.index = function(req, res) {
  112. var settingForm;
  113. settingForm = Config.setupCofigFormData('crowi', req.config);
  114. return res.render('admin/customize', {
  115. settingForm: settingForm,
  116. });
  117. };
  118. // app.get('/admin/notification' , admin.notification.index);
  119. actions.notification = {};
  120. actions.notification.index = function(req, res) {
  121. var config = crowi.getConfig();
  122. var UpdatePost = crowi.model('UpdatePost');
  123. var slackSetting = Config.setupCofigFormData('notification', config);
  124. var hasSlackWebClientConfig = Config.hasSlackWebClientConfig(config);
  125. var hasSlackIwhUrl = Config.hasSlackIwhUrl(config);
  126. var hasSlackToken = Config.hasSlackToken(config);
  127. var slack = crowi.slack;
  128. var slackAuthUrl = '';
  129. if (!Config.hasSlackWebClientConfig(req.config)) {
  130. slackSetting['slack:clientId'] = '';
  131. slackSetting['slack:clientSecret'] = '';
  132. }
  133. else {
  134. slackAuthUrl = slack.getAuthorizeURL();
  135. }
  136. if (!Config.hasSlackIwhUrl(req.config)) {
  137. slackSetting['slack:incomingWebhookUrl'] = '';
  138. }
  139. if (req.session.slackSetting) {
  140. slackSetting = req.session.slackSetting;
  141. req.session.slackSetting = null;
  142. }
  143. UpdatePost.findAll()
  144. .then(function(settings) {
  145. return res.render('admin/notification', {
  146. settings,
  147. slackSetting,
  148. hasSlackWebClientConfig,
  149. hasSlackIwhUrl,
  150. hasSlackToken,
  151. slackAuthUrl
  152. });
  153. });
  154. };
  155. // app.post('/admin/notification/slackSetting' , admin.notification.slackauth);
  156. actions.notification.slackSetting = function(req, res) {
  157. var slackSetting = req.form.slackSetting;
  158. req.session.slackSetting = slackSetting;
  159. if (req.form.isValid) {
  160. Config.updateNamespaceByArray('notification', slackSetting, function(err, config) {
  161. Config.updateConfigCache('notification', config);
  162. req.flash('successMessage', ['Successfully Updated!']);
  163. req.session.slackSetting = null;
  164. // Re-setup
  165. crowi.setupSlack().then(function() {
  166. return res.redirect('/admin/notification');
  167. });
  168. });
  169. } else {
  170. req.flash('errorMessage', req.form.errors);
  171. return res.redirect('/admin/notification');
  172. }
  173. };
  174. // app.get('/admin/notification/slackAuth' , admin.notification.slackauth);
  175. actions.notification.slackAuth = function(req, res) {
  176. const code = req.query.code;
  177. const config = crowi.getConfig();
  178. if (!code || !Config.hasSlackConfig(req.config)) {
  179. return res.redirect('/admin/notification');
  180. }
  181. const slack = crowi.slack;
  182. slack.getOauthAccessToken(code)
  183. .then(data => {
  184. debug('oauth response', data);
  185. Config.updateNamespaceByArray('notification', {'slack:token': data.access_token}, function(err, config) {
  186. if (err) {
  187. req.flash('errorMessage', ['Failed to save access_token. Please try again.']);
  188. } else {
  189. Config.updateConfigCache('notification', config);
  190. req.flash('successMessage', ['Successfully Connected!']);
  191. }
  192. return res.redirect('/admin/notification');
  193. });
  194. }).catch(err => {
  195. debug('oauth response ERROR', err);
  196. req.flash('errorMessage', ['Failed to fetch access_token. Please do connect again.']);
  197. return res.redirect('/admin/notification');
  198. });
  199. };
  200. actions.search = {};
  201. actions.search.index = function(req, res) {
  202. var search = crowi.getSearcher();
  203. if (!search) {
  204. return res.redirect('/admin');
  205. }
  206. return res.render('admin/search', {
  207. });
  208. };
  209. // app.post('/admin/notification/slackIwhSetting' , admin.notification.slackIwhSetting);
  210. actions.notification.slackIwhSetting = function(req, res) {
  211. var slackIwhSetting = req.form.slackIwhSetting;
  212. if (req.form.isValid) {
  213. Config.updateNamespaceByArray('notification', slackIwhSetting, function(err, config) {
  214. Config.updateConfigCache('notification', config);
  215. req.flash('successMessage', ['Successfully Updated!']);
  216. // Re-setup
  217. crowi.setupSlack().then(function() {
  218. return res.redirect('/admin/notification#slack-incoming-webhooks');
  219. });
  220. });
  221. } else {
  222. req.flash('errorMessage', req.form.errors);
  223. return res.redirect('/admin/notification#slack-incoming-webhooks');
  224. }
  225. };
  226. // app.post('/admin/notification/slackSetting/disconnect' , admin.notification.disconnectFromSlack);
  227. actions.notification.disconnectFromSlack = function(req, res) {
  228. const config = crowi.getConfig();
  229. const slack = crowi.slack;
  230. Config.updateNamespaceByArray('notification', {'slack:token': ''}, function(err, config) {
  231. Config.updateConfigCache('notification', config);
  232. req.flash('successMessage', ['Successfully Disconnected!']);
  233. return res.redirect('/admin/notification');
  234. });
  235. };
  236. actions.search.buildIndex = function(req, res) {
  237. var search = crowi.getSearcher();
  238. if (!search) {
  239. return res.redirect('/admin');
  240. }
  241. return new Promise(function(resolve, reject) {
  242. search.deleteIndex()
  243. .then(function(data) {
  244. debug('Index deleted.');
  245. resolve();
  246. }).catch(function(err) {
  247. debug('Delete index Error, but if it is initialize, its ok.', err);
  248. resolve();
  249. });
  250. })
  251. .then(function() {
  252. return search.buildIndex()
  253. })
  254. .then(function(data) {
  255. if (!data.errors) {
  256. debug('Index created.');
  257. }
  258. return search.addAllPages();
  259. })
  260. .then(function(data) {
  261. if (!data.errors) {
  262. debug('Data is successfully indexed.');
  263. req.flash('successMessage', 'Data is successfully indexed.');
  264. } else {
  265. debug('Data index error.', data.errors);
  266. req.flash('errorMessage', `Data index error: ${data.errors}`);
  267. }
  268. return res.redirect('/admin/search');
  269. })
  270. .catch(function(err) {
  271. debug('Error', err);
  272. req.flash('errorMessage', `Error: ${err}`);
  273. return res.redirect('/admin/search');
  274. });
  275. };
  276. actions.user = {};
  277. actions.user.index = function(req, res) {
  278. var page = parseInt(req.query.page) || 1;
  279. User.findUsersWithPagination({page: page}, function(err, result) {
  280. const pager = createPager(result.total, result.limit, result.page, result.pages, MAX_PAGE_LIST);
  281. return res.render('admin/users', {
  282. users: result.docs,
  283. pager: pager
  284. });
  285. });
  286. };
  287. actions.user.invite = function(req, res) {
  288. var form = req.form.inviteForm;
  289. var toSendEmail = form.sendEmail || false;
  290. if (req.form.isValid) {
  291. User.createUsersByInvitation(form.emailList.split('\n'), toSendEmail, function(err, userList) {
  292. if (err) {
  293. req.flash('errorMessage', req.form.errors.join('\n'));
  294. } else {
  295. req.flash('createdUser', userList);
  296. }
  297. return res.redirect('/admin/users');
  298. });
  299. } else {
  300. req.flash('errorMessage', req.form.errors.join('\n'));
  301. return res.redirect('/admin/users');
  302. }
  303. };
  304. actions.user.makeAdmin = function(req, res) {
  305. var id = req.params.id;
  306. User.findById(id, function(err, userData) {
  307. userData.makeAdmin(function(err, userData) {
  308. if (err === null) {
  309. req.flash('successMessage', userData.name + 'さんのアカウントを管理者に設定しました。');
  310. } else {
  311. req.flash('errorMessage', '更新に失敗しました。');
  312. debug(err, userData);
  313. }
  314. return res.redirect('/admin/users');
  315. });
  316. });
  317. };
  318. actions.user.removeFromAdmin = function(req, res) {
  319. var id = req.params.id;
  320. User.findById(id, function(err, userData) {
  321. userData.removeFromAdmin(function(err, userData) {
  322. if (err === null) {
  323. req.flash('successMessage', userData.name + 'さんのアカウントを管理者から外しました。');
  324. } else {
  325. req.flash('errorMessage', '更新に失敗しました。');
  326. debug(err, userData);
  327. }
  328. return res.redirect('/admin/users');
  329. });
  330. });
  331. };
  332. actions.user.activate = function(req, res) {
  333. var id = req.params.id;
  334. User.findById(id, function(err, userData) {
  335. userData.statusActivate(function(err, userData) {
  336. if (err === null) {
  337. req.flash('successMessage', userData.name + 'さんのアカウントを承認しました');
  338. } else {
  339. req.flash('errorMessage', '更新に失敗しました。');
  340. debug(err, userData);
  341. }
  342. return res.redirect('/admin/users');
  343. });
  344. });
  345. };
  346. actions.user.suspend = function(req, res) {
  347. var id = req.params.id;
  348. User.findById(id, function(err, userData) {
  349. userData.statusSuspend(function(err, userData) {
  350. if (err === null) {
  351. req.flash('successMessage', userData.name + 'さんのアカウントを利用停止にしました');
  352. } else {
  353. req.flash('errorMessage', '更新に失敗しました。');
  354. debug(err, userData);
  355. }
  356. return res.redirect('/admin/users');
  357. });
  358. });
  359. };
  360. actions.user.remove = function(req, res) {
  361. var id = req.params.id;
  362. let username = '';
  363. return new Promise((resolve, reject) => {
  364. User.findById(id, (err, userData) => {
  365. username = userData.username;
  366. return resolve(userData);
  367. });
  368. })
  369. .then((userData) => {
  370. return new Promise((resolve, reject) => {
  371. userData.statusDelete((err, userData) => {
  372. if (err) {
  373. reject(err);
  374. }
  375. resolve(userData);
  376. });
  377. });
  378. })
  379. .then((userData) => {
  380. // remove all External Accounts
  381. ExternalAccount.remove({user: userData})
  382. .then((err) => {
  383. if (err) {
  384. throw new Error(err.message);
  385. }
  386. return userData;
  387. })
  388. })
  389. .then((userData) => {
  390. return Page.removePageByPath(`/user/${username}`)
  391. .then(() => userData);
  392. })
  393. .then((userData) => {
  394. req.flash('successMessage', `${username} さんのアカウントを削除しました`);
  395. return res.redirect('/admin/users');
  396. })
  397. .catch((err) => {
  398. req.flash('errorMessage', '削除に失敗しました。');
  399. return res.redirect('/admin/users');
  400. });
  401. };
  402. // これやったときの relation の挙動未確認
  403. actions.user.removeCompletely = function(req, res) {
  404. // ユーザーの物理削除
  405. var id = req.params.id;
  406. User.removeCompletelyById(id, function(err, removed) {
  407. if (err) {
  408. debug('Error while removing user.', err, id);
  409. req.flash('errorMessage', '完全な削除に失敗しました。');
  410. } else {
  411. req.flash('successMessage', '削除しました');
  412. }
  413. return res.redirect('/admin/users');
  414. });
  415. };
  416. // app.post('/_api/admin/users.resetPassword' , admin.api.usersResetPassword);
  417. actions.user.resetPassword = function(req, res) {
  418. const id = req.body.user_id;
  419. const User = crowi.model('User');
  420. User.resetPasswordByRandomString(id)
  421. .then(function(data) {
  422. data.user = User.filterToPublicFields(data.user);
  423. return res.json(ApiResponse.success(data));
  424. }).catch(function(err) {
  425. debug('Error on reseting password', err);
  426. return res.json(ApiResponse.error('Error'));
  427. });
  428. }
  429. actions.externalAccount = {};
  430. actions.externalAccount.index = function(req, res) {
  431. const page = parseInt(req.query.page) || 1;
  432. ExternalAccount.findAllWithPagination({page})
  433. .then((result) => {
  434. const pager = createPager(result.total, result.limit, result.page, result.pages, MAX_PAGE_LIST);
  435. return res.render('admin/external-accounts', {
  436. accounts: result.docs,
  437. pager: pager
  438. })
  439. });
  440. };
  441. actions.externalAccount.remove = function(req, res) {
  442. const accountId = req.params.id;
  443. ExternalAccount.findOneAndRemove({accountId})
  444. .then((result) => {
  445. if (result == null) {
  446. req.flash('errorMessage', '削除に失敗しました。');
  447. return res.redirect('/admin/users/external-accounts');
  448. }
  449. else {
  450. req.flash('successMessage', `外部アカウント '${accountId}' を削除しました`);
  451. return res.redirect('/admin/users/external-accounts');
  452. }
  453. });
  454. };
  455. actions.userGroup = {};
  456. actions.userGroup.index = function (req, res) {
  457. var page = parseInt(req.query.page) || 1;
  458. UserGroup.findUserGroupsWithPagination({ page: page }, function (err, result) {
  459. const pager = createPager(result.total, result.limit, result.page, result.pages, MAX_PAGE_LIST);
  460. return res.render('admin/user_groups', {
  461. userGroups: result.docs,
  462. pager: pager
  463. });
  464. });
  465. };
  466. // actions.userGroup.create = function (req, res) {
  467. // var form = req.form.createGroupForm;
  468. // // var toSendEmail = form.sendEmail || false;
  469. // // if (req.form.isValid) {
  470. // User.createUsersByInvitation(form.userGroupName, function (err, newUserGroup) {
  471. // if (err) {
  472. // req.flash('errorMessage', req.form.errors.join('\n'));
  473. // } else {
  474. // req.flash('createdUserGroup', newUserGroup);
  475. // }
  476. // return res.redirect('/admin/user_groups');
  477. // });
  478. // // } else {
  479. // // req.flash('errorMessage', req.form.errors.join('\n'));
  480. // // return res.redirect('/admin/user_groups');
  481. // // }
  482. // };
  483. actions.api = {};
  484. actions.api.appSetting = function(req, res) {
  485. var form = req.form.settingForm;
  486. if (req.form.isValid) {
  487. debug('form content', form);
  488. // mail setting ならここで validation
  489. if (form['mail:from']) {
  490. validateMailSetting(req, form, function(err, data) {
  491. debug('Error validate mail setting: ', err, data);
  492. if (err) {
  493. req.form.errors.push('SMTPを利用したテストメール送信に失敗しました。設定をみなおしてください。');
  494. return res.json({status: false, message: req.form.errors.join('\n')});
  495. }
  496. return saveSetting(req, res, form);
  497. });
  498. } else {
  499. return saveSetting(req, res, form);
  500. }
  501. } else {
  502. return res.json({status: false, message: req.form.errors.join('\n')});
  503. }
  504. };
  505. actions.api.securitySetting = function(req, res) {
  506. var form = req.form.settingForm;
  507. if (req.form.isValid) {
  508. debug('form content', form);
  509. return saveSetting(req, res, form);
  510. } else {
  511. return res.json({status: false, message: req.form.errors.join('\n')});
  512. }
  513. };
  514. actions.api.securityPassportLdapSetting = function(req, res) {
  515. var form = req.form.settingForm;
  516. if (!req.form.isValid) {
  517. return res.json({status: false, message: req.form.errors.join('\n')});
  518. }
  519. debug('form content', form);
  520. return saveSettingAsync(form)
  521. .then(() => {
  522. const config = crowi.getConfig();
  523. // reset strategy
  524. crowi.passportService.resetLdapStrategy();
  525. // setup strategy
  526. if (Config.isEnabledPassportLdap(config)) {
  527. crowi.passportService.setupLdapStrategy(true);
  528. }
  529. return;
  530. })
  531. .then(() => {
  532. res.json({status: true});
  533. });
  534. };
  535. actions.api.customizeSetting = function(req, res) {
  536. var form = req.form.settingForm;
  537. if (req.form.isValid) {
  538. debug('form content', form);
  539. return saveSetting(req, res, form);
  540. } else {
  541. return res.json({status: false, message: req.form.errors.join('\n')});
  542. }
  543. }
  544. // app.post('/_api/admin/notifications.add' , admin.api.notificationAdd);
  545. actions.api.notificationAdd = function(req, res) {
  546. var UpdatePost = crowi.model('UpdatePost');
  547. var pathPattern = req.body.pathPattern;
  548. var channel = req.body.channel;
  549. debug('notification.add', pathPattern, channel);
  550. UpdatePost.create(pathPattern, channel, req.user)
  551. .then(function(doc) {
  552. debug('Successfully save updatePost', doc);
  553. // fixme: うーん
  554. doc.creator = doc.creator._id.toString();
  555. return res.json(ApiResponse.success({updatePost: doc}));
  556. }).catch(function(err) {
  557. debug('Failed to save updatePost', err);
  558. return res.json(ApiResponse.error());
  559. });
  560. };
  561. // app.post('/_api/admin/notifications.remove' , admin.api.notificationRemove);
  562. actions.api.notificationRemove = function(req, res) {
  563. var UpdatePost = crowi.model('UpdatePost');
  564. var id = req.body.id;
  565. UpdatePost.remove(id)
  566. .then(function() {
  567. debug('Successfully remove updatePost');
  568. return res.json(ApiResponse.success({}));
  569. }).catch(function(err) {
  570. debug('Failed to remove updatePost', err);
  571. return res.json(ApiResponse.error());
  572. });
  573. };
  574. // app.get('/_api/admin/users.search' , admin.api.userSearch);
  575. actions.api.usersSearch = function(req, res) {
  576. const User = crowi.model('User');
  577. const email =req.query.email;
  578. User.findUsersByPartOfEmail(email, {})
  579. .then(users => {
  580. const result = {
  581. data: users
  582. };
  583. return res.json(ApiResponse.success(result));
  584. }).catch(err => {
  585. return res.json(ApiResponse.error());
  586. });
  587. };
  588. /**
  589. * save settings, update config cache, and response json
  590. *
  591. * @param {any} req
  592. * @param {any} res
  593. * @param {any} form
  594. */
  595. function saveSetting(req, res, form)
  596. {
  597. Config.updateNamespaceByArray('crowi', form, function(err, config) {
  598. Config.updateConfigCache('crowi', config);
  599. return res.json({status: true});
  600. });
  601. }
  602. /**
  603. * save settings, update config cache ONLY. (this method don't response json)
  604. *
  605. * @param {any} form
  606. * @returns
  607. */
  608. function saveSettingAsync(form) {
  609. return new Promise((resolve, reject) => {
  610. Config.updateNamespaceByArray('crowi', form, (err, config) => {
  611. if (err) {
  612. return reject(err)
  613. };
  614. Config.updateConfigCache('crowi', config);
  615. return resolve();
  616. });
  617. });
  618. }
  619. function validateMailSetting(req, form, callback)
  620. {
  621. var mailer = crowi.mailer;
  622. var option = {
  623. host: form['mail:smtpHost'],
  624. port: form['mail:smtpPort'],
  625. };
  626. if (form['mail:smtpUser'] && form['mail:smtpPassword']) {
  627. option.auth = {
  628. user: form['mail:smtpUser'],
  629. pass: form['mail:smtpPassword'],
  630. };
  631. }
  632. if (option.port === 465) {
  633. option.secure = true;
  634. }
  635. var smtpClient = mailer.createSMTPClient(option);
  636. debug('mailer setup for validate SMTP setting', smtpClient);
  637. smtpClient.sendMail({
  638. to: req.user.email,
  639. subject: 'Wiki管理設定のアップデートによるメール通知',
  640. text: 'このメールは、WikiのSMTP設定のアップデートにより送信されています。'
  641. }, callback);
  642. }
  643. return actions;
  644. };