implemented quick E-mail and SIG invitation emails
This commit is contained in:
@@ -162,4 +162,9 @@ public interface SIGContext extends SearchMode
|
||||
|
||||
public abstract void delete() throws DataException, AccessError;
|
||||
|
||||
public abstract void sendInvitation(String address, String personal_message)
|
||||
throws AccessError, DataException, EmailException;
|
||||
|
||||
public abstract boolean canSendInvitation();
|
||||
|
||||
} // end interface SIGContext
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Community System.
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
@@ -71,4 +71,11 @@ public interface UserProfile
|
||||
|
||||
public abstract String getDescription();
|
||||
|
||||
public abstract boolean isAnonymous();
|
||||
|
||||
public abstract boolean canSendQuickEmail();
|
||||
|
||||
public abstract void sendQuickEmail(String subject, String text)
|
||||
throws AccessError, DataException, EmailException;
|
||||
|
||||
} // end interface UserProfile
|
||||
|
||||
@@ -1458,6 +1458,24 @@ class ConferenceUserContextImpl implements ConferenceContext, ConferenceBackend
|
||||
|
||||
} // end userIsAnonymous
|
||||
|
||||
public String realUserName()
|
||||
{
|
||||
return sig.realUserName();
|
||||
|
||||
} // end realUserName
|
||||
|
||||
public String realEmailAddress() throws DataException
|
||||
{
|
||||
return sig.realEmailAddress();
|
||||
|
||||
} // end realEmailAddress
|
||||
|
||||
public String realFullName() throws DataException
|
||||
{
|
||||
return sig.realFullName();
|
||||
|
||||
} // end realFullName
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface SIGBackend
|
||||
*--------------------------------------------------------------------------------
|
||||
|
||||
@@ -20,6 +20,7 @@ package com.silverwrist.venice.core.impl;
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import org.apache.log4j.*;
|
||||
import com.silverwrist.util.StringUtil;
|
||||
import com.silverwrist.venice.db.*;
|
||||
import com.silverwrist.venice.security.Capability;
|
||||
import com.silverwrist.venice.security.DefaultLevels;
|
||||
@@ -387,7 +388,7 @@ class SIGUserContextImpl implements SIGContext, SIGBackend
|
||||
conn = datapool.getConnection();
|
||||
|
||||
// load the profile for the user
|
||||
return new UserProfileImpl(engine,conn,getSIGData().getHostUID(),
|
||||
return new UserProfileImpl(engine,user,conn,getSIGData().getHostUID(),
|
||||
Capability.canSeeHiddenContactFields(user.realBaseLevel()));
|
||||
|
||||
} // end try
|
||||
@@ -1221,6 +1222,55 @@ class SIGUserContextImpl implements SIGContext, SIGBackend
|
||||
|
||||
} // end delete
|
||||
|
||||
public void sendInvitation(String address, String personal_message)
|
||||
throws AccessError, DataException, EmailException
|
||||
{
|
||||
if (user.userIsAnonymous())
|
||||
throw new AccessError("You must be logged in to send an invitation.");
|
||||
|
||||
SIGData my_sig = getSIGData();
|
||||
my_sig.testMembership(level,is_member);
|
||||
|
||||
// Prepare the message text to be sent to the user.
|
||||
boolean is_pub = my_sig.isPublicSIG();
|
||||
String msg = engine.getStockMessage(is_pub ? "invite-public" : "invite-private");
|
||||
String signame = my_sig.getName();
|
||||
msg = StringUtil.replaceAllInstances(msg,"$SIGNAME",signame);
|
||||
msg = StringUtil.replaceAllInstances(msg,"$SIGALIAS",my_sig.getAlias());
|
||||
if (!is_pub)
|
||||
msg = StringUtil.replaceAllInstances(msg,"$JOINKEY",my_sig.getJoinKey());
|
||||
msg = StringUtil.replaceAllInstances(msg,"$PERSONAL",personal_message);
|
||||
msg = StringUtil.replaceAllInstances(msg,"$FULLNAME",user.realFullName());
|
||||
String uname = user.realUserName();
|
||||
msg = StringUtil.replaceAllInstances(msg,"$USERNAME",uname);
|
||||
StringBuffer msg_buf = new StringBuffer(msg);
|
||||
msg_buf.append("\n\n--\n").append(engine.getStockMessage("signature"));
|
||||
|
||||
// Prepare the subject line to be sent to the user.
|
||||
String subject = engine.getStockMessage("subj-invite");
|
||||
subject = StringUtil.replaceAllInstances(subject,"$SIGNAME",signame);
|
||||
|
||||
// Get a SimpleEmailer object, set it up, and send it.
|
||||
SimpleEmailer em = engine.createEmailer();
|
||||
em.setFrom(uname,user.realEmailAddress());
|
||||
em.setTo(address);
|
||||
em.setSubject(subject);
|
||||
em.setText(msg_buf.toString());
|
||||
em.send();
|
||||
|
||||
} // end sendInvitation
|
||||
|
||||
public boolean canSendInvitation()
|
||||
{
|
||||
if (user.userIsAnonymous())
|
||||
return false;
|
||||
SIGData sd = getSIGDataNE();
|
||||
if (sd==null)
|
||||
return false;
|
||||
return sd.checkMembership(level,is_member);
|
||||
|
||||
} // end canSendInvitation
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface UserBackend
|
||||
*--------------------------------------------------------------------------------
|
||||
@@ -1256,6 +1306,24 @@ class SIGUserContextImpl implements SIGContext, SIGBackend
|
||||
|
||||
} // end userIsAnonymous
|
||||
|
||||
public String realUserName()
|
||||
{
|
||||
return user.realUserName();
|
||||
|
||||
} // end realUserName
|
||||
|
||||
public String realEmailAddress() throws DataException
|
||||
{
|
||||
return user.realEmailAddress();
|
||||
|
||||
} // end realEmailAddress
|
||||
|
||||
public String realFullName() throws DataException
|
||||
{
|
||||
return user.realFullName();
|
||||
|
||||
} // end realFullName
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Implementations from interface SIGBackend
|
||||
*--------------------------------------------------------------------------------
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Community System.
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
@@ -25,10 +25,20 @@ import com.silverwrist.venice.core.InternalStateError;
|
||||
|
||||
class SimpleEmailer
|
||||
{
|
||||
private Session session; // the email session
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Attributes
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private Session session; // the email session
|
||||
private MimeMessage msg; // the message being composed
|
||||
|
||||
public SimpleEmailer(Properties props, javax.mail.Session session)
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
SimpleEmailer(Properties props, javax.mail.Session session)
|
||||
{
|
||||
this.session = session;
|
||||
msg = new MimeMessage(session);
|
||||
@@ -54,6 +64,11 @@ class SimpleEmailer
|
||||
|
||||
} // end constructor
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External operations
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public void setTo(String to) throws EmailException
|
||||
{
|
||||
try
|
||||
@@ -75,6 +90,37 @@ class SimpleEmailer
|
||||
|
||||
} // end setTo
|
||||
|
||||
public void setFrom(String from_name, String from_addr) throws EmailException
|
||||
{
|
||||
try
|
||||
{ // set the "from" address
|
||||
InternetAddress addr = new InternetAddress(from_addr);
|
||||
addr.setPersonal(from_name);
|
||||
msg.setFrom(addr);
|
||||
|
||||
// make sure the "Sender" address reflects our email address
|
||||
InternetAddress sender = InternetAddress.getLocalAddress(session);
|
||||
msg.setHeader("Sender",sender.toString());
|
||||
|
||||
} // end try
|
||||
catch (AddressException e1)
|
||||
{ // the address was somehow invalid
|
||||
throw new EmailException("invalid email sender address",e1);
|
||||
|
||||
} // end catch
|
||||
catch (MessagingException e2)
|
||||
{ // msg.setRecipients should NOT be throwing a MessageException here!
|
||||
throw new InternalStateError("condition should not apply to message here",e2);
|
||||
|
||||
} // end catch
|
||||
catch (java.io.UnsupportedEncodingException e3)
|
||||
{ // we can't really have that happen here, either!
|
||||
throw new InternalStateError("condition should not apply to message here",e3);
|
||||
|
||||
} // end catch
|
||||
|
||||
} // end setFrom
|
||||
|
||||
public void setSubject(String subject)
|
||||
{
|
||||
try
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Community System.
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
@@ -31,4 +31,10 @@ public interface UserBackend
|
||||
|
||||
public abstract boolean userIsAnonymous();
|
||||
|
||||
public abstract String realUserName();
|
||||
|
||||
public abstract String realEmailAddress() throws DataException;
|
||||
|
||||
public abstract String realFullName() throws DataException;
|
||||
|
||||
} // end interface UserBackend
|
||||
|
||||
@@ -58,6 +58,7 @@ class UserContextImpl implements UserContext, UserBackend
|
||||
private String description; // personal description
|
||||
private String my_email = null; // my email address (cached)
|
||||
private String my_pseud = null; // my pseud (cached)
|
||||
private String full_name = null; // my full name (cached)
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructor
|
||||
@@ -439,8 +440,10 @@ class UserContextImpl implements UserContext, UserBackend
|
||||
rc = new ContactInfoImpl(uid);
|
||||
if (my_email==null)
|
||||
my_email = rc.getEmail();
|
||||
if (full_name==null)
|
||||
full_name = rc.getGivenName() + " " + rc.getFamilyName();
|
||||
if (my_pseud==null)
|
||||
my_pseud = rc.getGivenName() + " " + rc.getFamilyName();
|
||||
my_pseud = full_name;
|
||||
return rc;
|
||||
|
||||
} // end getContactInfo
|
||||
@@ -485,7 +488,8 @@ class UserContextImpl implements UserContext, UserBackend
|
||||
|
||||
} // end if
|
||||
|
||||
my_pseud = ci.getGivenName() + " " + ci.getFamilyName(); // update this field
|
||||
full_name = ci.getGivenName() + " " + ci.getFamilyName(); // update this field
|
||||
my_pseud = full_name;
|
||||
|
||||
if (my_email==null) // filling in, this is not necessarily the first time
|
||||
my_email = ci.getEmail();
|
||||
@@ -568,7 +572,7 @@ class UserContextImpl implements UserContext, UserBackend
|
||||
try
|
||||
{ // retrieve a connection from the data pool
|
||||
conn = datapool.getConnection();
|
||||
UserProfileImpl prof = new UserProfileImpl(engine,conn,xusername,
|
||||
UserProfileImpl prof = new UserProfileImpl(engine,this,conn,xusername,
|
||||
Capability.canSeeHiddenContactFields(level));
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("...found it!");
|
||||
@@ -599,7 +603,8 @@ class UserContextImpl implements UserContext, UserBackend
|
||||
try
|
||||
{ // retrieve a connection from the data pool
|
||||
conn = datapool.getConnection();
|
||||
UserProfileImpl prof = new UserProfileImpl(engine,conn,xuid,Capability.canSeeHiddenContactFields(level));
|
||||
UserProfileImpl prof = new UserProfileImpl(engine,this,conn,xuid,
|
||||
Capability.canSeeHiddenContactFields(level));
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("...found it!");
|
||||
return prof;
|
||||
@@ -925,6 +930,28 @@ class UserContextImpl implements UserContext, UserBackend
|
||||
|
||||
} // end userIsAnonymous
|
||||
|
||||
public String realUserName()
|
||||
{
|
||||
return username;
|
||||
|
||||
} // end realUserName
|
||||
|
||||
public String realEmailAddress() throws DataException
|
||||
{
|
||||
if (my_email==null)
|
||||
getContactInfo();
|
||||
return my_email;
|
||||
|
||||
} // end realEmailAddress
|
||||
|
||||
public String realFullName() throws DataException
|
||||
{
|
||||
if (full_name==null)
|
||||
getContactInfo();
|
||||
return full_name;
|
||||
|
||||
} // end realFullName
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Operations private to implementation package
|
||||
*--------------------------------------------------------------------------------
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
* WARRANTY OF ANY KIND, either express or implied. See the License for the specific
|
||||
* language governing rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is the Venice Web Community System.
|
||||
* The Original Code is the Venice Web Communities System.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Eric J. Bowersox <erbo@silcom.com>,
|
||||
* for Silverwrist Design Studios. Portions created by Eric J. Bowersox are
|
||||
@@ -19,12 +19,26 @@ package com.silverwrist.venice.core.impl;
|
||||
|
||||
import java.sql.*;
|
||||
import java.util.*;
|
||||
import org.apache.log4j.*;
|
||||
import com.silverwrist.venice.core.*;
|
||||
import com.silverwrist.venice.db.*;
|
||||
|
||||
class UserProfileImpl implements UserProfile
|
||||
{
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Static data members
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private static Category logger = Category.getInstance(UserProfileImpl.class.getName());
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Attributes
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private EngineBackend engine; // the engine back end
|
||||
private UserBackend user; // the user that generated this profile
|
||||
private int uid; // user ID
|
||||
private String username; // user name
|
||||
private String given_name; // given name ("first name")
|
||||
@@ -50,64 +64,95 @@ class UserProfileImpl implements UserProfile
|
||||
private java.util.Date last_login; // date of last login
|
||||
private java.util.Date last_update; // date of last update
|
||||
private String real_email; // real email address
|
||||
private boolean is_anon; // is this the anonymous account?
|
||||
|
||||
UserProfileImpl(EngineBackend engine, Connection conn, String username, boolean override)
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Constructors
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
UserProfileImpl(EngineBackend engine, UserBackend user, Connection conn, String username, boolean override)
|
||||
throws DataException, SQLException
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("load UserProfileImpl by name: " + username + " (" + override + ")");
|
||||
this.engine = engine;
|
||||
this.user = user;
|
||||
|
||||
// first retrieve from the users table
|
||||
Statement stmt = conn.createStatement();
|
||||
StringBuffer sql = new StringBuffer("SELECT uid, username, contactid, created, lastaccess, description "
|
||||
+ "FROM users WHERE username = '");
|
||||
StringBuffer sql = new StringBuffer("SELECT uid, username, contactid, created, lastaccess, description, "
|
||||
+ "is_anon FROM users WHERE username = '");
|
||||
sql.append(SQLUtil.encodeString(username)).append("';");
|
||||
ResultSet rs = stmt.executeQuery(sql.toString());
|
||||
if (!(rs.next()))
|
||||
{ // we didn't find the user
|
||||
logger.error("unable to find user with username '" + username + "'");
|
||||
throw new DataException("User '" + username + "' not found.");
|
||||
|
||||
} // end if
|
||||
|
||||
// load the "elementary" fields
|
||||
this.uid = rs.getInt("uid");
|
||||
this.username = rs.getString("username");
|
||||
int contact_id = rs.getInt("contactid");
|
||||
created = SQLUtil.getFullDateTime(rs,"created");
|
||||
last_login = SQLUtil.getFullDateTime(rs,"lastaccess");
|
||||
descr = rs.getString("description");
|
||||
this.uid = rs.getInt(1);
|
||||
this.username = rs.getString(2);
|
||||
int contact_id = rs.getInt(3);
|
||||
created = SQLUtil.getFullDateTime(rs,4);
|
||||
last_login = SQLUtil.getFullDateTime(rs,5);
|
||||
descr = rs.getString(6);
|
||||
is_anon = rs.getBoolean(7);
|
||||
|
||||
loadContact(conn,contact_id,override);
|
||||
|
||||
} // end constructor
|
||||
|
||||
UserProfileImpl(EngineBackend engine, Connection conn, int uid, boolean override)
|
||||
UserProfileImpl(EngineBackend engine, UserBackend user, Connection conn, int uid, boolean override)
|
||||
throws DataException, SQLException
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("load UserProfileImpl by UID: " + uid + " (" + override + ")");
|
||||
this.engine = engine;
|
||||
this.user = user;
|
||||
|
||||
// first retrieve from the users table
|
||||
Statement stmt = conn.createStatement();
|
||||
StringBuffer sql = new StringBuffer("SELECT uid, username, contactid, created, lastaccess, description "
|
||||
+ "FROM users WHERE uid = ");
|
||||
StringBuffer sql = new StringBuffer("SELECT uid, username, contactid, created, lastaccess, description, "
|
||||
+ "is_anon FROM users WHERE uid = ");
|
||||
sql.append(uid).append(';');
|
||||
ResultSet rs = stmt.executeQuery(sql.toString());
|
||||
if (!(rs.next()))
|
||||
{ // we didn't find user
|
||||
logger.error("unable to find user with uid " + uid);
|
||||
throw new DataException("User #" + String.valueOf(uid) + " not found.");
|
||||
|
||||
} // end if
|
||||
|
||||
// load the "elementary" fields
|
||||
this.uid = rs.getInt("uid");
|
||||
this.username = rs.getString("username");
|
||||
int contact_id = rs.getInt("contactid");
|
||||
created = SQLUtil.getFullDateTime(rs,"created");
|
||||
last_login = SQLUtil.getFullDateTime(rs,"lastaccess");
|
||||
descr = rs.getString("description");
|
||||
this.uid = rs.getInt(1);
|
||||
this.username = rs.getString(2);
|
||||
int contact_id = rs.getInt(3);
|
||||
created = SQLUtil.getFullDateTime(rs,4);
|
||||
last_login = SQLUtil.getFullDateTime(rs,5);
|
||||
descr = rs.getString(6);
|
||||
is_anon = rs.getBoolean(7);
|
||||
|
||||
loadContact(conn,contact_id,override);
|
||||
|
||||
} // end constructor
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* Internal functions
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
private void loadContact(Connection conn, int contact_id, boolean override) throws SQLException
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("loadContact for contact ID " + contact_id + " (" + override + ")");
|
||||
|
||||
Statement stmt = conn.createStatement();
|
||||
StringBuffer sql = new StringBuffer("SELECT * FROM contacts WHERE contactid = ");
|
||||
sql.append(contact_id).append(';');
|
||||
|
||||
ResultSet rs = stmt.executeQuery(sql.toString());
|
||||
if (rs.next())
|
||||
{ // load all the record data
|
||||
@@ -194,6 +239,11 @@ class UserProfileImpl implements UserProfile
|
||||
|
||||
} // end loadContact
|
||||
|
||||
/*--------------------------------------------------------------------------------
|
||||
* External operations
|
||||
*--------------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
public int getUID()
|
||||
{
|
||||
return uid;
|
||||
@@ -344,4 +394,49 @@ class UserProfileImpl implements UserProfile
|
||||
|
||||
} // end getDescription
|
||||
|
||||
public boolean isAnonymous()
|
||||
{
|
||||
return is_anon;
|
||||
|
||||
} // end isAnonymous
|
||||
|
||||
public boolean canSendQuickEmail()
|
||||
{
|
||||
return !is_anon && !(user.userIsAnonymous());
|
||||
|
||||
} // end canSendQuickEmail
|
||||
|
||||
public void sendQuickEmail(String subject, String text) throws AccessError, DataException, EmailException
|
||||
{
|
||||
if (logger.isDebugEnabled())
|
||||
logger.debug("Send Quick E-Mail (from uid " + user.realUID() + " to uid " + uid + ")");
|
||||
|
||||
if (user.userIsAnonymous())
|
||||
{ // we can't send quick emails if we're anonymous!
|
||||
logger.error("sending user is not logged in.");
|
||||
throw new AccessError("You must be logged in to send a quick E-mail message.");
|
||||
|
||||
} // end if
|
||||
|
||||
if (is_anon)
|
||||
{ // we can't send quick emails to the anonymous user
|
||||
logger.error("target user is the anonymous user");
|
||||
throw new AccessError("You cannot send email to the anonymous user.");
|
||||
|
||||
} // end if
|
||||
|
||||
// assemble the full text
|
||||
StringBuffer text_buf = new StringBuffer(text);
|
||||
text_buf.append("\n\n--\n").append(engine.getStockMessage("signature"));
|
||||
|
||||
// create the emailer object, fill it in, and send it
|
||||
SimpleEmailer em = engine.createEmailer();
|
||||
em.setFrom(user.realUserName(),user.realEmailAddress());
|
||||
em.setTo(real_email);
|
||||
em.setSubject(subject);
|
||||
em.setText(text_buf.toString());
|
||||
em.send();
|
||||
|
||||
} // end sendQuickEmail
|
||||
|
||||
} // end class UserProfileImpl
|
||||
|
||||
Reference in New Issue
Block a user