Created
February 15, 2017 11:49
-
-
Save ppillip/124831c92b090dcf864e4844a534304c to your computer and use it in GitHub Desktop.
login.server.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Meteor.methods({ | |
regUser : function(info){ | |
console.log(info); | |
//1 | |
Accounts.createUser(info); | |
return true; | |
}, | |
changePwd : function(userId,newPassword){ | |
if(Meteor.user().username !== 'admin'){ | |
console.log('관리자 이외에 변경 금지'); | |
return; | |
} | |
console.log(Meteor.user().username,userId,newPassword); | |
Accounts.setPassword(userId, newPassword); | |
}, | |
removeUser : function(userId){ | |
if(Meteor.users.findOne({_id:userId}).username == 'admin'){ | |
console.log('관리자 계정 삭제금지'); | |
return; | |
}; | |
if(Meteor.user().username !== 'admin'){ | |
console.log('관리자 이외에 삭제 금지'); | |
return; | |
} | |
Meteor.users.remove({_id:userId}); | |
} | |
}); | |
//로그인 시도할경우 호출됨. 여기서 로그아웃 하면 끝 | |
Accounts.validateLoginAttempt(function(obj){ | |
//db.users.update({username:'admin'},{$set:{'profile.isAllowed':true}}); | |
//db.users.update({username:'admin'},{$set:{'profile.isAdmin':true}}); | |
var user = obj.user; | |
return user.profile && user.profile.isAllowed; | |
}); | |
/* | |
* 사용자등록시 필터 되는 부분 | |
* */ | |
Accounts.onCreateUser(function(options, user) { | |
console.log('Accounts.onCreateUser',user); | |
user.profile = JSON.parse(JSON.stringify(options)); | |
user.profile.isAdmin = false; //기본이 어드민 아님 | |
user.profile.isAllowed = false; //기본이 로그인안됨 | |
delete user.profile.password; | |
return user; | |
}); | |
/* | |
* 등록시 validation 을 하는 부분 , 자동 호출됨. | |
* */ | |
Accounts.validateNewUser(function (user) { | |
console.log('Accounts.validateNewUser',user); | |
if (user.username && user.username.length >= 3){ | |
return true; | |
} else { | |
console.error('username 이 짧다'); | |
throw new Meteor.Error(403, "사용자 명은 적어도 3자 이상입니다."); | |
} | |
}); | |
Accounts.onLogin(function(obj){ | |
console.log("로그인성공",obj.user.username); | |
}); | |
Accounts.onLoginFailure(function(a){ | |
console.error("Accounts.onLoginFailure : 로그인실패"); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment