Advertisement
Guest User

Untitled

a guest
May 23rd, 2017
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 7.24 KB | None | 0 0
  1. public with sharing class SignUpController {
  2.    
  3.     public Boolean resend {get; set;}
  4.     public String firstName {get; set;}
  5.     public String lastName {get; set;}
  6.     public String email {get; set;}
  7.     public String password   {get; set;}
  8.     public String speciality {get; set;}
  9.     public Boolean checkTerms  {get; set;}
  10.     public String userName {get; set;}
  11.     public String Id {get; set;}
  12.     public String zip {get; set;}
  13.     public String phone {get; set;}
  14.     public String confirmPassword   {get; set;}
  15.     public Contact contact2 {get; set;}
  16.    
  17.     public Boolean index {get; set;}
  18.     public Boolean checkTermsRender {get; set;}
  19.        
  20.     private boolean isValidPassword() {
  21.         return password != '' && password == confirmPassword;
  22.     }
  23.    
  24.     public SignUpController() {
  25.        
  26.        Schema.DescribeFieldResult d = Contact.Speciality__c.getDescribe();
  27.        contact2 = new Contact();
  28.                        
  29.        for(Schema.PicklistEntry p: d.getPicklistValues()) {
  30.           contact2.Speciality__c =  p.getLabel();  
  31.           break;
  32.        }   
  33.     }
  34.    
  35.     public List<SelectOption> getSpecialities() {
  36.    
  37.        List<SelectOption> options = new List<SelectOption>();
  38.        Schema.DescribeFieldResult d = Contact.Speciality__c.getDescribe();
  39.        contact2 = new Contact();
  40.                        
  41.        for(Schema.PicklistEntry p: d.getPicklistValues()) {
  42.           contact2.Speciality__c =  p.getLabel();  
  43.           break;
  44.        }
  45.        
  46.        for(Schema.PicklistEntry p: d.getPicklistValues()) {            
  47.           options.add(new SelectOption(p.getLabel(),  p.getLabel() ));
  48.        }
  49.                              
  50.        return options;
  51.     }
  52.        
  53.     public PageReference doUpdateDoctor() {
  54.        
  55.        // it's okay if password is null - we'll send the user a random password in that case
  56.        if (!isValidPassword()) {
  57.          ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'The password and the confirmation aren\'t the same!'));
  58.          return null;
  59.        }
  60.        
  61.        List<Contact> d = [SELECT Id FROM Contact WHERE id = :id];
  62.        
  63.        if ( d.size() == 0 ) {
  64.      
  65.         ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'The ID is invalid !'));
  66.         return null;
  67.        }
  68.                    
  69.        Contact c = d.get(0);
  70.        
  71.        if (c.Id == null) {
  72.          
  73.          ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'The ID is invalid '));
  74.          return null;
  75.        }    
  76.        
  77.        //c.FirstName = firstName; c.Email = email; c.LastName = lastName; c.especialidad__c  = especialidad; c.Phone   = phone; c.MailingPostalCode  = zip; c.matricula__c  = matricula;
  78.        c.Phone   = phone;
  79.        c.MailingPostalCode  = zip;
  80.        update c;
  81.        
  82.        User u = new User();
  83.        u.ContactId = c.id;
  84.        u.Username = email;
  85.        u.firstName = firstName;
  86.        u.LastName = lastName;
  87.        u.Email = email;
  88.        u.ProfileId = Label.ProfileDoctor;
  89.        u.CommunityNickname = email;
  90.        String userId = Site.createPortalUser(u, Label.AccountDoctor, password);
  91.  
  92.        if (userId != null) {
  93.          if (password != null && password.length() > 1) {
  94.      
  95.          return Site.login(email, password, 'Need');
  96.          }
  97.        }
  98.      
  99.       return null;        
  100.     }
  101.  
  102.     public PageReference doNewDoctor() {
  103.      
  104.       email = contact2.email;
  105.       if ((email != null) && (email != '') && (email != 'null')) {
  106.      
  107.        try {
  108.         List<Contact> d = [SELECT Id, Email FROM Contact WHERE email = :email AND IsDeleted = false];
  109.      
  110.         if ( d.size() > 0 ) {
  111.           resend = true;
  112.           ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, d.get(0).Email + ', you\'re already a member of ScrubStorm!. To login again, please enter your existing Email and Password in the upper right.'));
  113.        
  114.           return null;
  115.         }    
  116.            
  117.         } catch(Exception e) {
  118.          
  119.           ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please try again' ));
  120.           return null;
  121.         }
  122.        
  123.       }
  124.      
  125.        Boolean error = false;
  126.        
  127.        if (firstName == '') {              
  128.          ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please, Insert your First Name' ));
  129.          error = true;              
  130.        }
  131.  
  132.        if (lastName == '') {
  133.          ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please, Insert your Last Name' ));
  134.          error = true;          
  135.        }
  136.        
  137.        if ((email == null) || (email == '') || (email == 'null')) {
  138.           ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please, Insert your email' ));
  139.           error = true;
  140.        }
  141.        
  142.        if ((contact2.Speciality__c == null) || (contact2.Speciality__c == '') || (contact2.Speciality__c == 'null')) {
  143.           ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please, Insert your Speciality' ));
  144.           error = true;
  145.        }
  146.        
  147.        
  148.        /*if (userName == '') {
  149.          ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please, Insert your User Name' ));
  150.          error = true;
  151.        }*/
  152.        
  153.        /*if (password == '') {
  154.          ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please, Insert your password' ));
  155.          error = true;
  156.        }*/
  157.        
  158.        if ((contact2.Speciality__c == null) || (contact2.Speciality__c == '') || (contact2.Speciality__c == 'null')) {
  159.           ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please, Insert your Speciality' ));
  160.           error = true;
  161.        }
  162.                  
  163.        if (error) {
  164.          return null;
  165.        }
  166.        
  167.        String parameters = '?email=' + email;
  168.        parameters += '&speciality=' + contact2.Speciality__c;
  169.        parameters += '&firstName=' + firstName;
  170.        parameters += '&lastName=' + lastName;
  171.        /*parameters += '&userName=' + userName;
  172.        parameters += '&password=' + password;*/
  173.              
  174.        PageReference page = new PageReference('/apex/TermsPolicy' + parameters);
  175.        page.setRedirect(true);
  176.      
  177.        return page;
  178.     }
  179.    
  180.    
  181.     public static testmethod void test() {
  182.    
  183.         SignUpController testing = new SignUpController();
  184.         testing.isValidPassword();
  185.        
  186.        
  187.         Contact c = new Contact(LastName = 'Claros',email = 'sclaros@gmail.com');
  188.         insert c;
  189.        
  190.         testing.Id = c.Id;
  191.        
  192.         testing.getSpecialities();
  193.        
  194.         testing.password = '123';
  195.         testing.confirmPassword ='123';
  196.         testing.firstname = 'sebastian';
  197.         testing.lastname = 'claros';
  198.        
  199.         testing.doUpdateDoctor();
  200.         testing.email = 's.claros@gmail.com';
  201.         testing.contact2.Email = 'sclaros@gmail.com';
  202.         testing.doNewDoctor();
  203.         testing.email = 'sclaros@gmail.com';
  204.         testing.doNewDoctor();
  205.            
  206.         testing.confirmPassword ='1234';
  207.         testing.doUpdateDoctor();
  208.            
  209.         testing.contact2.Email = 'sclaros222@gmail.com';
  210.         testing.doNewDoctor();
  211.     }
  212.  
  213. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement