Last active
August 29, 2015 14:11
-
-
Save junojisan/7b6529a09257e1ecf423 to your computer and use it in GitHub Desktop.
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
global class AutocreatedRegHandler1418352596451 implements Auth.RegistrationHandler{ | |
global boolean canCreateUser(Auth.UserData data) { | |
// 以下のTwitterスクリーン名の時、ユーザ登録を許可する | |
Set<String> s = new Set<String>{'junojisan'}; | |
if(s.contains(data.username)) { | |
return true; | |
} | |
return false; | |
} | |
global User createUser(Id portalId, Auth.UserData data){ | |
if(!canCreateUser(data)) { | |
return null; | |
} | |
// 取引先に"SNSログインユーザを管理するための取引先"を登録しておく | |
Account a = [SELECT Id FROM account WHERE name = | |
'SNSログインユーザを管理するための取引先']; | |
Contact c = new Contact(); | |
c.accountId = a.Id; | |
c.email = 'hoge@piyo.test.com'; | |
c.firstName = data.fullName; | |
c.lastName = data.username; | |
insert(c); | |
User u = new User(); | |
Profile p = [SELECT Id FROM profile WHERE name='Customer Community Login User']; | |
u.username = data.username + '@piyo.test.com'; | |
u.email = 'hoge@piyo.test.com'; | |
u.lastName = data.username; | |
u.firstName = data.fullName; | |
String alias = data.username; | |
if(alias.length() > 8) { | |
alias = alias.substring(0, 8); | |
} | |
u.alias = alias; | |
u.languagelocalekey = 'ja'; | |
u.localesidkey = UserInfo.getLocale(); | |
u.emailEncodingKey = 'UTF-8'; | |
u.timeZoneSidKey = 'Asia/Tokyo'; | |
u.profileId = p.Id; | |
u.contactId = c.Id; | |
return u; | |
} | |
global void updateUser(Id userId, Id portalId, Auth.UserData data){ | |
User u = new User(id=userId); | |
u.email = 'hoge@piyo.test.com'; | |
u.lastName = data.username; | |
u.firstName = data.fullName; | |
update(u); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment