Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public with sharing class SignUpController {
- public Boolean resend {get; set;}
- public String firstName {get; set;}
- public String lastName {get; set;}
- public String email {get; set;}
- public String password {get; set;}
- public String speciality {get; set;}
- public Boolean checkTerms {get; set;}
- public String userName {get; set;}
- public String Id {get; set;}
- public String zip {get; set;}
- public String phone {get; set;}
- public String confirmPassword {get; set;}
- public Contact contact2 {get; set;}
- public Boolean index {get; set;}
- public Boolean checkTermsRender {get; set;}
- private boolean isValidPassword() {
- return password != '' && password == confirmPassword;
- }
- public SignUpController() {
- Schema.DescribeFieldResult d = Contact.Speciality__c.getDescribe();
- contact2 = new Contact();
- for(Schema.PicklistEntry p: d.getPicklistValues()) {
- contact2.Speciality__c = p.getLabel();
- break;
- }
- }
- public List<SelectOption> getSpecialities() {
- List<SelectOption> options = new List<SelectOption>();
- Schema.DescribeFieldResult d = Contact.Speciality__c.getDescribe();
- contact2 = new Contact();
- for(Schema.PicklistEntry p: d.getPicklistValues()) {
- contact2.Speciality__c = p.getLabel();
- break;
- }
- for(Schema.PicklistEntry p: d.getPicklistValues()) {
- options.add(new SelectOption(p.getLabel(), p.getLabel() ));
- }
- return options;
- }
- public PageReference doUpdateDoctor() {
- // it's okay if password is null - we'll send the user a random password in that case
- if (!isValidPassword()) {
- ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'The password and the confirmation aren\'t the same!'));
- return null;
- }
- List<Contact> d = [SELECT Id FROM Contact WHERE id = :id];
- if ( d.size() == 0 ) {
- ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'The ID is invalid !'));
- return null;
- }
- Contact c = d.get(0);
- if (c.Id == null) {
- ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'The ID is invalid '));
- return null;
- }
- //c.FirstName = firstName; c.Email = email; c.LastName = lastName; c.especialidad__c = especialidad; c.Phone = phone; c.MailingPostalCode = zip; c.matricula__c = matricula;
- c.Phone = phone;
- c.MailingPostalCode = zip;
- update c;
- User u = new User();
- u.ContactId = c.id;
- u.Username = email;
- u.firstName = firstName;
- u.LastName = lastName;
- u.Email = email;
- u.ProfileId = Label.ProfileDoctor;
- u.CommunityNickname = email;
- String userId = Site.createPortalUser(u, Label.AccountDoctor, password);
- if (userId != null) {
- if (password != null && password.length() > 1) {
- return Site.login(email, password, 'Need');
- }
- }
- return null;
- }
- public PageReference doNewDoctor() {
- email = contact2.email;
- if ((email != null) && (email != '') && (email != 'null')) {
- try {
- List<Contact> d = [SELECT Id, Email FROM Contact WHERE email = :email AND IsDeleted = false];
- if ( d.size() > 0 ) {
- resend = true;
- 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.'));
- return null;
- }
- } catch(Exception e) {
- ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please try again' ));
- return null;
- }
- }
- Boolean error = false;
- if (firstName == '') {
- ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please, Insert your First Name' ));
- error = true;
- }
- if (lastName == '') {
- ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please, Insert your Last Name' ));
- error = true;
- }
- if ((email == null) || (email == '') || (email == 'null')) {
- ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please, Insert your email' ));
- error = true;
- }
- if ((contact2.Speciality__c == null) || (contact2.Speciality__c == '') || (contact2.Speciality__c == 'null')) {
- ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please, Insert your Speciality' ));
- error = true;
- }
- /*if (userName == '') {
- ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please, Insert your User Name' ));
- error = true;
- }*/
- /*if (password == '') {
- ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please, Insert your password' ));
- error = true;
- }*/
- if ((contact2.Speciality__c == null) || (contact2.Speciality__c == '') || (contact2.Speciality__c == 'null')) {
- ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.ERROR, 'Please, Insert your Speciality' ));
- error = true;
- }
- if (error) {
- return null;
- }
- String parameters = '?email=' + email;
- parameters += '&speciality=' + contact2.Speciality__c;
- parameters += '&firstName=' + firstName;
- parameters += '&lastName=' + lastName;
- /*parameters += '&userName=' + userName;
- parameters += '&password=' + password;*/
- PageReference page = new PageReference('/apex/TermsPolicy' + parameters);
- page.setRedirect(true);
- return page;
- }
- public static testmethod void test() {
- SignUpController testing = new SignUpController();
- testing.isValidPassword();
- Contact c = new Contact(LastName = 'Claros',email = 'sclaros@gmail.com');
- insert c;
- testing.Id = c.Id;
- testing.getSpecialities();
- testing.password = '123';
- testing.confirmPassword ='123';
- testing.firstname = 'sebastian';
- testing.lastname = 'claros';
- testing.doUpdateDoctor();
- testing.email = 's.claros@gmail.com';
- testing.contact2.Email = 'sclaros@gmail.com';
- testing.doNewDoctor();
- testing.email = 'sclaros@gmail.com';
- testing.doNewDoctor();
- testing.confirmPassword ='1234';
- testing.doUpdateDoctor();
- testing.contact2.Email = 'sclaros222@gmail.com';
- testing.doNewDoctor();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement