"use strict";

let models = require("../model/mongo");

module.exports.init = function(router) {
  /**
   * 邮箱验证
  */
  router.post("/email/verify", async function(ctx, next) {
    let usermodel = models.user;
    let email = ctx.request.body.email;
    let emailRet = await usermodel.find({ email: email }).exec();
    if (emailRet.length) {
      ctx.status = 200;
      ctx.body = {
        success: false,
        msg: "邮箱已存在！"
      };
    } else {
      ctx.status = 200;
      ctx.body = {
        success: true,
        msg: "邮箱可用！"
      };
    }
  });
};

@@ -132,16 +132,25 @@
 (%22/email
+_username
 /verify%22
@@ -175,24 +175,24 @@
 tx, next) %7B%0A
-
     let user
@@ -252,16 +252,62 @@
 .email;%0A
+    let username = ctx.request.body.username;%0A
     let 
@@ -364,16 +364,91 @@
 exec();%0A
+    let usernameRet = await usermodel.find(%7B username: username %7D).exec();%0A
     if (
@@ -533,16 +533,16 @@
  false,%0A
-
         
@@ -560,24 +560,160 @@
 %EF%BC%81%22%0A      %7D;%0A
+    %7D else if (usernameRet.length) %7B%0A      ctx.status = 200;%0A      ctx.body = %7B%0A        success: false,%0A        msg: %22%E7%94%A8%E6%88%B7%E5%90%8D%E5%B7%B2%E5%AD%98%E5%9C%A8%EF%BC%81%22%0A      %7D;%0A
     %7D else %7B

add username verify