如何检查用户是否已在mysql中可用

时间:2016-10-06 11:17:26

标签: mysql sails.js

这里我存储用户名和密码。数据存储在mysql中,但我必须检查用户名是否已经可用

此外,如何在UI端获得响应以显示用户是否是创建者。(如在警报框中)

.factory('userDetailsFactory',function(){
var user = {};
return {
    setUserDetailsInFactory : function(val,$cookies,favoriteCookie,put,get){        
        user.useridFromSession = val[0].UserId;
        user.usernameFromSession = val[0].UserName;
        user.userroleFromSession = val[0].Role;
        user.clientidFromSession = val[0].ClientId;
        user.ip = "http://192.168.2.100:5000";

        user.mstrDashBoardSession = val[0].DashBoard;
        user.mstrClientLSession = val[0].ClientLogin;
        user.ClientRegistrationSession = val[0].ClientRegistration;
        user.mstrBustypeSession = val[0].mstrBustype;
        user.mstrBusCategorySession = val[0].mstrBusCategory;
        user.mstrSeatLayoutSession = val[0].mstrSeatLayout;
        user.mstrDesignationSession = val[0].mstrDesignation;
        user.mstrBusSession = val[0].mstrBus;
        user.mstrRouteSession = val[0].mstrRoute;
        user.mstrBranchSession = val[0].mstrBranch;
        user.mstrDeviceSession = val[0].mstrDevice;
        user.mstrServiceSession = val[0].mstrService;
        user.mstrRouteFareSession = val[0].mstrRouteFare;
        user.mstrNewUserSession = val[0].mstrNewUser;
        user.mstrPDAServiceAssignSession = val[0].mstrPDAServiceAssign;
        user.mstrUserRightSession = val[0].mstrUserRight;
        user.rptTripSheetSession = val[0].rptTripSheet;
        user.rptTripSummarySession = val[0].rptTripSummary;
        user.rptCargoSummaryFromSession = val[0].rptCargoSummary;
        user.rptBusMonthSession = val[0].rptBusMonth;
        user.rptDeviceSession = val[0].rptDevice;


        //console.log(user.useridFromSession);
        //console.log(user.usernameFromSession);
        //console.log(user.userroleFromSession);
    },getUserDetailsFromFactory : function(){
        return user;
    }
};

1 个答案:

答案 0 :(得分:0)

您可以使用findOrCreate

Signup.findOrCreate({
  username: username
}, {
  username: username,
  password: password
}).exec(<callback>);