users.userExists({
        username: username
      }, function(err, exists) {
        if (err) {
          users.close();
          console.error('Error testing if user exists: ' + err);
          response.error = '业务忙,请稍候重试';
          res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(response);
          return;
        } else if (exists) {
          users.close();
          response.error = '用户名已经存在';
          res.status(HttpStatus.CONFLICT).json(response);
          return;
        } else {
          users.emailExists(profile.email, function(err, exists) {
            console.log(profile.email +' ' + exists);
            if (err) {
              users.close();
              console.error('checking email error');
              response.error = '业务忙,请稍候重试';
              res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(response);
              return;
            } else if (exists) {
              users.close();
              response.error = '邮箱 ' + profile.email + ' 已存在';
              res.status(HttpStatus.CONFLICT).json(response);
              return;
            }
            users.createUser(username, password, profile, function(err, uid, hash) {
              if (err) {
                response.error = '生成用户错误';
                console.error('Failed to create user ' + err);
                res.status(HttpStatus.INTERNAL_SERVER_ERROR).json(response);
              } else {
                response.statusMessage = '成功生成用户';
                response.uid = uid;
                // best-effort without a callback
                res.json(response);
              }
            });
          });
        }
      })
这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。
V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。
V2EX is a community of developers, designers and creative people.