Guest User

Untitled

a guest
Feb 10th, 2018
478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.66 KB | None | 0 0
  1. @AuraEnabled
  2. public static String login(String username, String password, String startUrl, Boolean isEnglish) {
  3. String currentuserId;
  4. String tester;
  5. try{
  6. ApexPages.PageReference lgn = Site.login(username, password, startUrl);
  7.  
  8. if (isEnglish == null || isEnglish)
  9. lgn.getParameters().put('language','en_CA');
  10. else
  11. lgn.getParameters().put('language','fr');
  12.  
  13. currentuserId = UserInfo.getUserId();
  14. User currentUserInfo = [select Id, LanguageLocaleKey from User where username = :username];
  15. tester = currentuserId + ' ' + currentUserInfo.Id;
  16. system.debug('USER ' + currentUserInfo);
  17. if (currentUserInfo != null){
  18. //CRUD udpate #Unfuddle 311
  19. if(Schema.SobjectType.User.isAccessible() && Schema.SobjectType.User.isUpdateable()){
  20.  
  21. if(isEnglish == null || isEnglish){
  22. currentUserInfo.LanguageLocaleKey = 'en_US';
  23. }else{
  24. currentUserInfo.LanguageLocaleKey = 'fr';
  25. }
  26.  
  27. update currentUserInfo;
  28. }else{
  29. throw new AuraHandledException('Insufficient privileges to update a User, Contact System Administrator!');
  30. }
  31.  
  32.  
  33. }
  34. aura.redirect(lgn);
  35.  
  36. return null;
  37. }
  38. catch (Exception ex) {
  39. //return ex.getMessage();
  40. return Label.S360_PIF_Login_Error;
  41. }
  42.  
  43. @isTest
  44. public class S360_LightningLoginFormController_Test {
  45. public static testmethod void testLoginForm(){
  46. //create User
  47. User u = new User(
  48. ProfileId = [SELECT Id FROM Profile WHERE Name ='Business System Administrator'].Id,
  49. LastName = 'last',
  50. Email = 'test@gmail.com',
  51. Username = 'test1@gmail.com' + System.currentTimeMillis(),
  52. CompanyName = 'TEST',
  53. Title = 'title',
  54. Alias = 'alias',
  55. TimeZoneSidKey = 'America/Los_Angeles',
  56. EmailEncodingKey = 'UTF-8',
  57. LanguageLocaleKey ='fr',
  58. LocaleSidKey ='fr_CA');
  59. insert u;
  60.  
  61.  
  62. SiteRegisterController controller = new SiteRegisterController();
  63. controller.username = 'test@force.com';
  64. controller.email = 'test@force.com';
  65. controller.communityNickname = 'test';
  66. // registerUser always returns null when the page isn't accessed as a guest user
  67. System.assert(controller.registerUser() == null);
  68. controller.password = 'abcd1234';
  69. controller.confirmPassword = 'abcd123';
  70. System.assert(controller.registerUser() == null);
  71. //Site.createPortalUser('test@force.com','abcd1234','url');
  72. //Site.createPortalUser(u, accountId, password)
  73.  
  74. S360_LightningLoginFormController.login(u.Username,'sunlife','url',true);
Add Comment
Please, Sign In to add comment