Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @AuraEnabled
- public static String login(String username, String password, String startUrl, Boolean isEnglish) {
- String currentuserId;
- String tester;
- try{
- ApexPages.PageReference lgn = Site.login(username, password, startUrl);
- if (isEnglish == null || isEnglish)
- lgn.getParameters().put('language','en_CA');
- else
- lgn.getParameters().put('language','fr');
- currentuserId = UserInfo.getUserId();
- User currentUserInfo = [select Id, LanguageLocaleKey from User where username = :username];
- tester = currentuserId + ' ' + currentUserInfo.Id;
- system.debug('USER ' + currentUserInfo);
- if (currentUserInfo != null){
- //CRUD udpate #Unfuddle 311
- if(Schema.SobjectType.User.isAccessible() && Schema.SobjectType.User.isUpdateable()){
- if(isEnglish == null || isEnglish){
- currentUserInfo.LanguageLocaleKey = 'en_US';
- }else{
- currentUserInfo.LanguageLocaleKey = 'fr';
- }
- update currentUserInfo;
- }else{
- throw new AuraHandledException('Insufficient privileges to update a User, Contact System Administrator!');
- }
- }
- aura.redirect(lgn);
- return null;
- }
- catch (Exception ex) {
- //return ex.getMessage();
- return Label.S360_PIF_Login_Error;
- }
- @isTest
- public class S360_LightningLoginFormController_Test {
- public static testmethod void testLoginForm(){
- //create User
- User u = new User(
- ProfileId = [SELECT Id FROM Profile WHERE Name ='Business System Administrator'].Id,
- LastName = 'last',
- Email = 'test@gmail.com',
- Username = 'test1@gmail.com' + System.currentTimeMillis(),
- CompanyName = 'TEST',
- Title = 'title',
- Alias = 'alias',
- TimeZoneSidKey = 'America/Los_Angeles',
- EmailEncodingKey = 'UTF-8',
- LanguageLocaleKey ='fr',
- LocaleSidKey ='fr_CA');
- insert u;
- SiteRegisterController controller = new SiteRegisterController();
- controller.username = 'test@force.com';
- controller.email = 'test@force.com';
- controller.communityNickname = 'test';
- // registerUser always returns null when the page isn't accessed as a guest user
- System.assert(controller.registerUser() == null);
- controller.password = 'abcd1234';
- controller.confirmPassword = 'abcd123';
- System.assert(controller.registerUser() == null);
- //Site.createPortalUser('test@force.com','abcd1234','url');
- //Site.createPortalUser(u, accountId, password)
- S360_LightningLoginFormController.login(u.Username,'sunlife','url',true);
Add Comment
Please, Sign In to add comment