OpenMeetings(4)----新用户注册

用户登录与注册的主要代码都在WebContent\src\base\auth\checkLoginData.lzx文件中

    <simpleLabelButton labelid="123" name="_register" width="160" y="$once{ parent.height-40 }" 
        visible="false" x="510" height="22">
        <handler name="onclick">
            <![CDATA[
                this.parent._register.setAttribute('visible',false);
                if (this.parent.childObj != null) {
                    this.parent.childObj.destroy();
                }
                this.parent.childObj = new lz.registerNewUser(canvas,{
                                                    refObj:this.parent,
                                                    user_login_minimum_length:parent.user_login_minimum_length,
                                                    user_pass_minimum_length:parent.user_pass_minimum_length
                                                });
            ]]>
        </handler>
    </simpleLabelButton>
主界面中,点击【Not a member? 】按钮后,将调用registerNewUser(),跳出注册界面,填写好username, password, email等一系列信息后,点击【 Register】后将执行如下代码:

   <simpleLabelButton name="registerB" labelid="121" width="120" x="240" y="332">
    	<handler name="onclick">
            <![CDATA[
                var pwd1 = strtrim(this.parent.userpass1.getText());
                var pwd2 = strtrim(this.parent.userpass2.getText());   
                var login = strtrim(this.parent.username.getText());     
                var email = strtrim(this.parent.email.getText()); 
                if (pwd1!=pwd2) {
					new lz.rpcErrorDialog(canvas,{errorid:-6});
				} else if(pwd1.length<parent.user_pass_minimum_length 
						|| login<parent.user_login_minimum_length){
				    var addInfo = "<br/> "
				    					+ parent.user_pass_minimum_length + " / " 
				    					+ parent.user_login_minimum_length;
                    new lz.rpcErrorDialog(canvas,{errorid:-7,addInfo:addInfo});
                } else if (email=="") {
                    new lz.rpcErrorDialog(canvas,{errorid:-53});
                } else {
                    this.parent.regObject = new Array();
                    this.parent.regObject["SID"]=canvas.sessionId;
                    this.parent.regObject["Username"]=login;
                    this.parent.regObject["Userpass"]=this.parent.userpass1.getText();
                    this.parent.regObject["lastname"]=this.parent.lastname.getText();
                    this.parent.regObject["firstname"]=this.parent.firstname.getText();
                    this.parent.regObject["email"]=email;
                    this.parent.regObject["jNameTimeZone"]=this.parent._timeZone.getValue();
                    this.parent.regObject["age"]=0;
                    this.parent.regObject["street"]='';
                    this.parent.regObject["additionalname"]='';
                    this.parent.regObject["fax"]='';
                    this.parent.regObject["zip"]='';
                    this.parent.regObject["states_id"]=Number(this.parent._state.getValue());
                    this.parent.regObject["town"]='';
                    this.parent.regObject["language_id"]=this.parent.languages.getValue();
                    
                    this.parent.regObject["domain"]=canvas.rtmphostlocal; 
                    this.parent.regObject["port"]=canvas.red5httpport; 
                    this.parent.regObject["webapp"]=canvas.httpRootKey; 
                    
                    if( $debug ) Debug.write("parent.regObject: ",parent.regObject);
                    
                    this.parent.registerUserByObject.doCall();
                }
            ]]>
    	</handler>
    </simpleLabelButton> 

调用了registerUserByObject(), 具体实现如下:

     <netRemoteCallHib name="registerUserByObject" funcname="xmlcrm.registerUserByObject" 
     	remotecontext="$once{ canvas.thishib }" activeErrorHandler="true" >     
        <netparam>
        	<method name="getValue"> 
        		return this.parent.parent.regObject; 
        	</method>
        </netparam>           
         <handler name="ondata" args="value">
         	<![CDATA[
            //The onResult-Handler will be called be the rtmpconnection
            if ($debug) Debug.write("registerUserByObject: ",value);
			if (!(value<0)){
				//Debug.write("successfully registered");
                 new lz.rpcErrorDialog(canvas.main_content._content.inner,{errorid:-18});
                 this.parent.refObj.username.setAttribute('text',this.parent.username.getText());
                 this.parent.refObj.userpass.setAttribute('text',this.parent.userpass1.getText());
                 this.parent.close();
			} else if (value == -40) {
				this.parent.refObj.username.setAttribute('text',this.parent.username.getText());
                this.parent.refObj.userpass.setAttribute('text',this.parent.userpass1.getText());
                this.parent.close();
			}
			]]>
         </handler>  
     </netRemoteCallHib>

我们看到这是一个远程调用,它将调用服务器上的registerUserByObject()函数(在src\org\apache\openmeetings\remote\MainService.java中)

	public Long registerUserByObject(Object regObjectObj) {
		try {
			@SuppressWarnings("unchecked")
			Map<?, ?> regObject = (Map<Object, Object>) regObjectObj;

			String domain = regObject.get("domain").toString();
			String port = regObject.get("port").toString();
			String webapp = regObject.get("webapp").toString();

			String baseURL = "http://" + domain + ":" + port + webapp;
			if (port.equals("80")) {
				baseURL = "http://" + domain + webapp;
			} else if (port.equals("443")) {
				baseURL = "https://" + domain + webapp;
			}
			String tz = (String)regObject.get("jNameTimeZone");
			if (tz == null || tz.length() == 0) {
				//Empty tz
				return -55L;
			}
			return userManager.registerUser(regObject.get("Username")
					.toString(), regObject.get("Userpass").toString(),
					regObject.get("lastname").toString(),
					regObject.get("firstname").toString(),
					regObject.get("email").toString(), new Date(), regObject
							.get("street").toString(),
					regObject.get("additionalname").toString(),
					regObject.get("fax").toString(), regObject.get("zip")
							.toString(),
					Long.valueOf(regObject.get("states_id").toString())
							.longValue(), regObject.get("town").toString(),
					Long.valueOf(regObject.get("language_id").toString())
							.longValue(), "", false, baseURL, true,
					tz);
		} catch (Exception ex) {
			log.error("registerUserByObject", ex);
		}
		return new Long(-1);
	}

这里面又调用了userManager.registerUser(), 顺着代码一路跟踪下去,调用关系如下:

	public Long registerUser(String login, String Userpass, String lastname,
			String firstname, String email, Date age, String street,
			String additionalname, String fax, String zip, long states_id,
			String town, long language_id, String phone, boolean sendSMS, String baseURL,
			boolean generateSipUserData, String jNameTimeZone) {
		
		boolean sendConfirmation = baseURL != null
				&& !baseURL.isEmpty()
				&& 1 == configurationDao.getConfValue(
						"sendEmailWithVerficationCode", Integer.class, "0");
		
		return registerUser(login, Userpass, lastname, firstname, email, age,
				street, additionalname, fax, zip, states_id, town, language_id,
				phone, sendSMS, baseURL, generateSipUserData, jNameTimeZone, sendConfirmation);
	}

 |

 |

V

private Long registerUser(String login, String Userpass, String lastname,
			String firstname, String email, Date age, String street,
			String additionalname, String fax, String zip, long states_id,
			String town, long language_id, String phone, boolean sendSMS, String baseURL,
			boolean generateSipUserData, String jNameTimeZone, Boolean sendConfirmation) {
		try {
			// Checks if FrontEndUsers can register
			if ("1".equals(configurationDao.getConfValue(
					"allow_frontend_register", String.class, "0"))) {
				
				// TODO: Read and generate SIP-Data via RPC-Interface Issue 1098

				Long user_id = this.registerUserInit(3, 1, 0, 1, login,
						Userpass, lastname, firstname, email, age, street,
						additionalname, fax, zip, states_id, town, language_id,
						true, Arrays.asList(configurationDao.getConfValue(
								"default_domain_id", Long.class, null)), phone,
						sendSMS, baseURL,
						sendConfirmation, jNameTimeZone, false, "", "", false, true);

				if (sendConfirmation) {
					return new Long(-40);
				}

				return user_id;
			}
		} catch (Exception e) {
			log.error("[registerUser]", e);
		}
		return null;
	}

 |

 |

V
	public Long registerUserInit(long user_level, long level_id, int availible,
			int status, String login, String password, String lastname,
			String firstname, String email, Date age, String street,
			String additionalname, String fax, String zip, long states_id,
			String town, long language_id, boolean sendWelcomeMessage,
			List<Long> organisations, String phone, boolean sendSMS, String baseURL,
			Boolean sendConfirmation, String jname_timezone, Boolean forceTimeZoneCheck,
			String userOffers, String userSearchs, Boolean showContactData,
			Boolean showContactDataToContacts) throws Exception {
		return registerUserInit(user_level, level_id, availible,
				status, login, password, lastname,
				firstname, email, age, street,
				additionalname, fax, zip, states_id,
				town, language_id, sendWelcomeMessage,
				organisations, phone, sendSMS, baseURL,
				sendConfirmation,
				omTimeZoneDaoImpl.getOmTimeZone(jname_timezone), forceTimeZoneCheck,
				userOffers, userSearchs, showContactData,
				showContactDataToContacts);
	}

 |

 |

V
	public Long registerUserInit(long user_level, long level_id, int availible,
			int status, String login, String password, String lastname,
			String firstname, String email, Date age, String street,
			String additionalname, String fax, String zip, long states_id,
			String town, long language_id, boolean sendWelcomeMessage,
			List<Long> organisations, String phone, boolean sendSMS, String baseURL,
			Boolean sendConfirmation,
			OmTimeZone timezone, Boolean forceTimeZoneCheck,
			String userOffers, String userSearchs, Boolean showContactData,
			Boolean showContactDataToContacts) throws Exception {
		// TODO: make phone number persistent
		// User Level must be at least Admin
		// Moderators will get a temp update of there UserLevel to add Users to
		// their Group
		if (authLevelUtil.checkModLevel(user_level)) {

			Integer userLoginMinimumLength = configurationDao.getConfValue(
					"user.login.minimum.length", Integer.class, "4");
			if (userLoginMinimumLength == null) {
				throw new Exception(
						"user.login.minimum.length problem");
			}

			// Check for required data
			if (login.length() >= userLoginMinimumLength.intValue()) {
				// Check for duplicates
				boolean checkName = usersDao.checkUserLogin(login);
				boolean checkEmail = emailManagement.checkUserEMail(email);
				if (checkName && checkEmail) {

					String hash = cryptManager
							.getInstanceOfCrypt()
							.createPassPhrase(
									login
											+ CalendarPatterns
													.getDateWithTimeByMiliSeconds(new Date()));
					String link = baseURL + "activateUser?u=" + hash;

					if (sendWelcomeMessage && email.length() != 0) {
						// We need to pass the baseURL to check if this is
						// really set to be send
						String sendMail = emailManagement.sendMail(login,
								password, email, link, sendConfirmation);
						if (!sendMail.equals("success"))
							return new Long(-19);
					}
					Address adr =  new Address();
					adr.setStreet(street);
					adr.setZip(zip);
					adr.setTown(town);
					adr.setStates(statemanagement.getStateById(states_id));
					adr.setAdditionalname(additionalname);
					adr.setComment("");
					adr.setFax(fax);
					adr.setPhone(phone);
					adr.setEmail(email);

					// If this user needs first to click his E-Mail verification
					// code then set the status to 0
					if (sendConfirmation) {
						status = 0;
					}

					Long user_id = addUser(level_id, availible, status,
							firstname, login, lastname, language_id, password,
							adr, sendSMS, age, hash, timezone,
							forceTimeZoneCheck, userOffers, userSearchs,
							showContactData, showContactDataToContacts, organisations);
					log.debug("Added user-Id " + user_id);
					if (user_id == null) {
						return new Long(-111);
					}

					/*
					 * Long adress_emails_id =
					 * emailManagement.registerEmail(email, address_id,""); if
					 * (adress_emails_id==null) { return new Long(-112); }
					 */

					if (adr.getAdresses_id() > 0 && user_id > 0) {
						return user_id;
					} else {
						return new Long(-16);
					}
				} else {
					if (!checkName) {
						return new Long(-15);
					} else if (!checkEmail) {
						return new Long(-17);
					}
				}
			} else {
				return new Long(-13);
			}
		}
		return new Long(-1);
	}

 |

 |

V

	public Long addUser(long level_id, int availible, int status,
			String firstname, String login, String lastname, long language_id,
			String userpass, Address adress, boolean sendSMS, Date age, String hash,
			OmTimeZone timezone,
			Boolean forceTimeZoneCheck, String userOffers, String userSearchs,
			Boolean showContactData, Boolean showContactDataToContacts, List<Long> orgIds) {
		try {

			User users = new User();
			users.setFirstname(firstname);
			users.setLogin(login);
			users.setLastname(lastname);
			users.setAge(age);
			users.setAdresses(adress);
			users.setSendSMS(sendSMS);
			users.setAvailible(availible);
			users.setLastlogin(new Date());
			users.setLasttrans(new Long(0));
			users.setLevel_id(level_id);
			users.setStatus(status);
			users.setSalutations_id(1L);
			users.setStarttime(new Date());
			users.setActivatehash(hash);
			users.setOmTimeZone(timezone);
			users.setForceTimeZoneCheck(forceTimeZoneCheck);

			users.setUserOffers(userOffers);
			users.setUserSearchs(userSearchs);
			users.setShowContactData(showContactData);
			users.setShowContactDataToContacts(showContactDataToContacts);

			// this is needed cause the language is not a needed data at
			// registering
			if (language_id != 0) {
				users.setLanguage_id(new Long(language_id));
			} else {
				users.setLanguage_id(null);
			}
			users.updatePassword(cryptManager, configurationDao, userpass);
			users.setRegdate(new Date());
			users.setDeleted(false);
			
			//new user add organizations without checks
			if (orgIds != null) {
				List<Organisation_Users> orgList = users.getOrganisation_users();
				for (Long orgId : orgIds) {
					orgList.add(organisationManager.getOrgUser(orgId, null));
				}
			}
			return addUser(users);

		} catch (Exception ex2) {
			log.error("[registerUser]", ex2);
		}
		return null;
	}

 |

 |

V

最后将用户信息插入数据库。

	public Long addUser(User usr) {
		try {
			em.persist(usr);
			//em.refresh(usr);
			em.flush();

			return usr.getUser_id();
		} catch (Exception ex2) {
			log.error("[addUser]", ex2);
		}
		return null;
	}


到这里就完成了一个新用户的注册过程!

你可能感兴趣的:(OpenMeetings(4)----新用户注册)