Browse Source

Add public_email option for user

pull/6/head
Menci 7 years ago
parent
commit
e4edef6f3c
  1. 1
      models/user.js
  2. 6
      modules/api.js
  3. 2
      modules/user.js
  4. 14
      views/user.ejs
  5. 7
      views/user_edit.ejs

1
models/user.js

@ -37,6 +37,7 @@ let model = db.define('user', {
is_admin: { type: Sequelize.BOOLEAN }, is_admin: { type: Sequelize.BOOLEAN },
is_show: { type: Sequelize.BOOLEAN }, is_show: { type: Sequelize.BOOLEAN },
public_email: { type: Sequelize.BOOLEAN },
sex: { type: Sequelize.INTEGER } sex: { type: Sequelize.INTEGER }
}, { }, {

6
modules/api.js

@ -94,7 +94,8 @@ app.post('/api/sign_up', async (req, res) => {
user = await User.create({ user = await User.create({
username: req.body.username, username: req.body.username,
password: req.body.password, password: req.body.password,
email: req.body.email email: req.body.email,
public_email: true
}); });
await user.save(); await user.save();
@ -134,7 +135,8 @@ app.get('/api/sign_up/:token', async (req, res) => {
user = await User.create({ user = await User.create({
username: obj.username, username: obj.username,
password: obj.password, password: obj.password,
email: obj.email email: obj.email,
public_email: true
}); });
await user.save(); await user.save();

2
modules/user.js

@ -94,6 +94,7 @@ app.get('/user/:id', async (req, res) => {
let statistics = await user.getStatistics(); let statistics = await user.getStatistics();
await user.renderInformation(); await user.renderInformation();
user.emailVisible = user.public_email || user.allowedEdit;
res.render('user', { res.render('user', {
show_user: user, show_user: user,
@ -168,6 +169,7 @@ app.post('/user/:id/edit', async (req, res) => {
user.information = req.body.information; user.information = req.body.information;
user.sex = req.body.sex; user.sex = req.body.sex;
user.public_email = (req.body.public_email === 'on');
await user.save(); await user.save();

14
views/user.ejs

@ -49,12 +49,14 @@
<div class="ui bottom attached segment"><%= show_user.username %><% if (show_user.nameplate) { %><%- show_user.nameplate %><% } %></div> <div class="ui bottom attached segment"><%= show_user.username %><% if (show_user.nameplate) { %><%- show_user.nameplate %><% } %></div>
</div> </div>
</div> </div>
<div class="row"> <% if (show_user.emailVisible) { %>
<div class="column"> <div class="row">
<h4 class="ui top attached block header">Email</h4> <div class="column">
<div class="ui bottom attached segment" class="font-content"><%= show_user.email %></div> <h4 class="ui top attached block header">Email</h4>
</div> <div class="ui bottom attached segment" class="font-content"><%= show_user.email %></div>
</div> </div>
</div>
<% } %>
<div class="row"> <div class="row">
<div class="column"> <div class="column">
<h4 class="ui top attached block header">个性签名</h4> <h4 class="ui top attached block header">个性签名</h4>

7
views/user_edit.ejs

@ -25,6 +25,13 @@
<label for="email">Email</label> <label for="email">Email</label>
<input class="font-content" type="email" id="email" name="email" value="<%= edited_user.email %>"<% if (!user.allowedManage) { %> readonly<% } %>> <input class="font-content" type="email" id="email" name="email" value="<%= edited_user.email %>"<% if (!user.allowedManage) { %> readonly<% } %>>
</div> </div>
<div class="inline field">
<label class="ui header">公开 Email</label>
<div class="ui toggle checkbox">
<input id="public_email" name="public_email" type="checkbox" <% if (edited_user.public_email) { %> checked<% } %>>
<label> </label>
</div>
</div>
<div class="field"> <div class="field">
<label for="information">个性签名</label> <label for="information">个性签名</label>
<textarea class="font-content" rows="5" id="information" name="information"><%= edited_user.information %></textarea> <textarea class="font-content" rows="5" id="information" name="information"><%= edited_user.information %></textarea>

Loading…
Cancel
Save