Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public with sharing class ConfirmationPageController {
- //public String userName {get; set;}
- public String password {get; set;}
- public String confirmPassword {get; set;}
- public Contact contact2 {get; set;}
- public Boolean index {get; set;}
- public Boolean incorrectLink {get; set;}
- public Boolean userCreated {get; set;}
- public Boolean signUperror {get; set;}
- public Boolean showMessages {get; set;}
- private static Id PORTAL_ACCOUNT_ID = '001A0000005FfqY';
- public ConfirmationPageController() {
- String contactID = ApexPages.currentPage().getParameters().get('id');
- index = true;
- incorrectLink = false;
- userCreated = false;
- signUperror = false;
- showMessages = false;
- password = '';
- confirmPassword = '';
- try {
- contact2 = [SELECT Id,AccountId,FirstName,email,lastName,Speciality__c FROM Contact WHERE id = :contactID ];
- } catch (Exception e) {
- incorrectLink = true;
- index = false;
- }
- Apexpages.getMessages().clear();
- }
- public PageReference createUser() {
- Boolean error = false;
- showMessages = true;
- if (password == null || password == '') {
- ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please, Insert password'));
- error = true;
- }
- if (confirmPassword == null || confirmPassword == '') {
- ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please, Insert the password confirmation'));
- error = true;
- }
- if (error) {
- return null;
- }
- if (password != confirmPassword) {
- ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'The confirmation password is wrong'));
- return null;
- }
- User u = new User();
- u.ContactId = contact2.id;
- u.Username = contact2.Email;
- u.firstName = contact2.FirstName;
- u.LastName = contact2.LastName;
- u.Email = contact2.Email;
- u.ProfileId = Label.ProfileDoctor;
- u.CommunityNickname = contact2.Email;
- String userId = Site.createPortalUser(u,PORTAL_ACCOUNT_ID, password);
- if (userId != null) {
- if (password != null && password.length() > 1) {
- userCreated = true;
- index = false;
- Site.login(contact2.Email, password, '/BackgroundInfo');
- return null;
- }
- }
- PageReference page = new Pagereference('/BackgroundInfo');
- return null;
- }
- public static testMethod void testing() {
- Contact c = new Contact();
- c.FirstName = 'gonzalo';
- c.LastName = 'sosa';
- c.Email = 'test@email.com';
- insert c;
- Pagereference page = new Pagereference('/ConfirmationPage?id=' + c.Id);
- ConfirmationPageController controller = new ConfirmationPageController();
- Test.setCurrentPage(page);
- controller = new ConfirmationPageController();
- controller.createUser();
- controller.password = 'password';
- controller.createUser();
- controller.confirmPassword = 'password';
- controller.createUser();
- controller.createUser();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement