Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Added UI for list of friends. Changed profilePhoto and gravatarPhoto to Photo objects. Added email input for gravatar. Fixed SetProfilePhoto button #216

Merged
merged 11 commits into from

2 participants

Lauren Yew Amin Shali
Lauren Yew
Collaborator

Fixed #208
Fixed #157
Added to messages #147

Amin Shali
Collaborator

Well done. Have you tested it?

Amin Shali
Collaborator

I am gonna merge this for now.

Amin Shali amshali merged commit 35d4340 into from
Lauren Yew
Collaborator

I tested the UI for this.

Amin Shali
Collaborator

The list of friends still need some work.

Lauren Yew
Collaborator

What else does it need?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
95 app/controllers/Photos.java
View
@@ -34,6 +34,7 @@ public static void photos(Long ownerId) {
}
public static void getPhoto(Long photoId) {
+
Photo photo = Photo.findById(photoId);
if (photo == null) {
Application.notFound();
@@ -142,11 +143,11 @@ public static void changeBGImage()
public static void setProfilePhoto(Long photoId) {
- if(photoId != null){
+ Photo photo = Photo.findById(photoId);
+ if(photo != null){
User user = user();
- Photo photo = Photo.findById(photoId);
- if (photo.owner.equals(user())) {
- user.profile.profilePhoto = photoId;
+ if (photo.owner.equals(user)) {
+ user.profile.profilePhoto = photo;
user.profile.save();
}
}
@@ -175,7 +176,7 @@ public static void addProfilePhoto(File image) throws FileNotFoundException, IOE
else {
photo.save();
User user = user();
- user.profile.profilePhoto = photo.id;
+ user.profile.profilePhoto = photo;
user.profile.save();
}
}catch(FileNotFoundException f)
@@ -189,17 +190,17 @@ public static void addProfilePhoto(File image) throws FileNotFoundException, IOE
/**
* set gravatar to the profile photo
*/
- public static void setGravatar() throws FileNotFoundException, IOException
+ public static void setGravatar(String gravatarEmail) throws FileNotFoundException, IOException
{
//first takes the user's email and makes it into the correct hex string
User u = user();
- String hash = md5Hex((u.email.trim()).toLowerCase());
+ String hash = md5Hex((gravatarEmail.trim()).toLowerCase());
String urlPath = "http://www.gravatar.com/avatar/"+hash+".jpg"+
"?" +//parameters
"size=100&d=mm";
URL url = new URL(urlPath);
BufferedImage image = ImageIO.read(url);
- if(u.profile.gravatarPhoto == -1l){//don't yet have a gravatarPhoto
+ if(u.profile.gravatarPhoto == null){//don't yet have a gravatarPhoto
try{
File gravatar = new File(hash+".jpg");
ImageIO.write(image, "jpg",gravatar);
@@ -216,13 +217,13 @@ public static void setGravatar() throws FileNotFoundException, IOException
else {
photo.save();
User user = user();
- user.profile.profilePhoto = photo.id;
+ user.profile.profilePhoto = photo;
//set gravatarPhoto id
- u.profile.gravatarPhoto = photo.id;
+ u.profile.gravatarPhoto = photo;
user.profile.save();
}
-
+
gravatar.delete();
}
@@ -235,55 +236,53 @@ public static void setGravatar() throws FileNotFoundException, IOException
}
else//have already added the gravatar picture, so we need to displace pic.
{
- Photo oldPhoto = Photo.findById(u.profile.gravatarPhoto);
- File gravatar = new File(hash+".jpg");
- ImageIO.write(image, "jpg",gravatar);
+ Photo oldPhoto = Photo.findById(u.profile.gravatarPhoto.id);
+ try{
+ File gravatar = new File(hash+".jpg");
+ ImageIO.write(image, "jpg",gravatar);
- if(gravatar != null){
+ if(gravatar != null){
- shrinkImage(gravatar);
+ shrinkImage(gravatar);
- //create new blob
- Blob blob = new Blob();
- blob.set(new FileInputStream(gravatar),
- MimeTypes.getContentType(gravatar.getName()));
+ //create new blob
+ Blob blob = new Blob();
+ blob.set(new FileInputStream(gravatar),
+ MimeTypes.getContentType(gravatar.getName()));
- oldPhoto.image = blob;
- validation.match(oldPhoto.image.type(), IMAGE_TYPE);
- validation.max(oldPhoto.image.length(), MAX_FILE_SIZE);
+ oldPhoto.image = blob;
+ validation.match(oldPhoto.image.type(), IMAGE_TYPE);
+ validation.max(oldPhoto.image.length(), MAX_FILE_SIZE);
- if (validation.hasErrors()) {
- validation.keep(); /* Remember errors after redirect. */}
- else {
- oldPhoto.save();
- User user = user();
- user.profile.profilePhoto = oldPhoto.id;
+ if (validation.hasErrors()) {
+ validation.keep(); /* Remember errors after redirect. */}
+ else {
+ oldPhoto.save();
+ User user = user();
+ user.profile.profilePhoto = oldPhoto;
+
+ //set gravatarPhoto id
+ u.profile.gravatarPhoto = oldPhoto;
+ user.profile.save();
+ }
- //set gravatarPhoto id
- u.profile.gravatarPhoto = oldPhoto.id;
- user.profile.save();
}
+ gravatar.delete();//delete file. We don't need it
+ }
+ catch(Exception f)
+ {
+ redirect("https://en.gravatar.com/site/signup/");
}
-
- gravatar.delete();//delete file. We don't need it
}
+
+ //if reach here have successfully changed the gravatar so we reset the email
+ u.profile.gravatarEmail = gravatarEmail;
+ u.profile.save();
+
setProfilePhotoPage();//render page
}
- /**
- * helper method for gravtar. does hex
- * @param array
- * @return
- */
- private static String hex(byte[] array) {
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < array.length; ++i) {
- sb.append(Integer.toHexString((array[i]
- & 0xFF) | 0x100).substring(1,3));
- }
- return sb.toString();
- }
/**
* helper method for gravatar
@@ -295,7 +294,7 @@ private static String md5Hex (String message) {
try {
MessageDigest md =
MessageDigest.getInstance("MD5");
- return hex (md.digest(message.getBytes("CP1252")));
+ return Codec.byteToHexString(md.digest(message.getBytes("CP1252")));
} catch (NoSuchAlgorithmException e) {
} catch (UnsupportedEncodingException e) {
}
13 app/models/Profile.java
View
@@ -22,6 +22,7 @@
public User owner;
public String gender; // The user's gender:female or male
public String locale; // The user's locale (ISO Language Code and ISO Country
+ public String gravatarEmail;
@OneToOne
public User significantOther; // The user's significant other
@@ -29,8 +30,11 @@
public String bio; // The user's biography
public String interestedIn; //genders the user is intersted in: Male, Female, Both, Neither
- public Long profilePhoto; // The user's profile picture.
- public Long gravatarPhoto;
+
+ @OneToOne
+ public Photo profilePhoto; // The user's profile picture.
+ @OneToOne
+ public Photo gravatarPhoto;
public Date birthday; // The user's birthday, uses javascript: http://www.dynamicdrive.com/dynamicindex7/jasoncalendar.htm
@@ -100,8 +104,9 @@ public Profile(User owner) {
this.address = "";
this.website = "";
this.email = "";
- this.profilePhoto = Bootstrap.defaultProfilePhotoID;
- this.gravatarPhoto = -1l;
+ this.profilePhoto = Photo.findById(Bootstrap.defaultProfilePhotoID);
+ this.gravatarPhoto = null;
+ this.gravatarEmail = owner.email;
}
public Profile(User owner, String bio, String gender, String quotes, String phone, String website){
2  app/views/Messages/inbox.html
View
@@ -30,7 +30,7 @@
<div class="hideable">
<div class="left">
<img style="width: 50px; height: 50px;"
- src="@{Photos.getPhoto(item.author.profile.profilePhoto)}" />
+ src="@{Photos.getPhoto(item.author.profile.profilePhoto.id)}" />
</div>
<div class="individual-msg-metadata">
#{timeago date:item.updatedAt /}
17 app/views/Photos/setProfilePhotoPage.html
View
@@ -11,8 +11,12 @@
</ul>
#{/ifErrors}
- <a class="button" href="@{Photos.setGravatar()}"><b>&{'photo.useGravatar'}</b></a>
- <br>
+ #{form @Photos.setGravatar(), enctype:'multipart/form-data'}
+ <b>Gravatar Email: </b><input type=text name=gravatarEmail
+ value="${currentUser.profile.gravatarEmail}" />
+ <input type=submit class="button" value=&{'photo.useGravatar'} />
+ #{/form}
+
<a href="https://en.gravatar.com/site/signup/">&{'photo.signUpGravatar'}</a>
<br>&{'photo.gravatarNote'}</br>
<br>
@@ -23,12 +27,13 @@
name="image" /> <input type="submit" name="submit" value=&{'photo.upload'} />
#{/form} <br> <b>&{'photo.useExistingPhoto'}</b> <br>
+
<ul class="photo-list">
#{list items:photos, as:'photo' }
- <li><img src="@{Photos.getPhoto(photo.id)}" width="120"
- height="150" /> #{if currentUser.equals(photo.owner)} #{form
- @Photos.setProfilePhoto(photo.id)} <input type="submit"
- name="submit" value=&{'photo.setAsProfilePhoto'} /> #{/form} #{/if}</li>
+ <img src="@{Photos.getPhoto(photo.id)}" width="120" height="150" />
+ <a class = "button" href="@{Photos.setProfilePhoto(photo.id)}">
+ &{'photo.setAsProfilePhoto'}</a> <br>
#{/list}
+
</ul>
</div>
41 app/views/Relationships/relationships.html
View
@@ -6,12 +6,41 @@
<hr/>
<br />
+
+%{boolean toggle = true;}%
+<table>
#{list items:user.confirmedFriends(), as:'friendship'}
-<a href="@{Application.about(friendship.to.id)}">${
- friendship.to.name }</a>
-<a id="friend-button" href="@{Relationships.unFriend(friendship.id)}">remove
- friend</a>
-<br />
-#{/list}
+<tr>
+#{if (toggle == true)}
+<td>
+<div style="background-color:white; width = 100%; align=left">
+ <img class="thumbnail" style = "width: 30px; height: 30px; vertical-align: middle"
+ src=@{Photos.getPhoto(friendship.to.profile.profilePhoto.id)} ALIGN=LEFT />
+ <a href="@{Application.about(friendship.to.id)}">${
+ friendship.to.name }</a>
+ <br />
+ <a id="friend-button" href="@{Relationships.unFriend(friendship.id)}">remove</a>
+ <br />
+ %{toggle = false;}%
+</div>
+</td>
+#{/if}
+#{else}
+<td>
+<div style="background-color:rgb(232, 232, 232); width=100%; align = left">
+ <img class="thumbnail" style = "width: 30px; height: 30px; vertical-align: middle"
+ src=@{Photos.getPhoto(friendship.to.profile.profilePhoto.id)} ALIGN=LEFT />
+ <a href="@{Application.about(friendship.to.id)}">${
+ friendship.to.name }</a>
+ <br />
+ <a id="friend-button" href="@{Relationships.unFriend(friendship.id)}">remove</a>
+ <br />
+ %{toggle = true;}%
+</div>
+</td>
+#{/else}
+</tr>
+#{/list}
+</table>
</div>
2  app/views/Subscriptions/subscriptions.html
View
@@ -18,7 +18,7 @@
<div class="hideable">
<div class="left">
<img style="width: 50px; height: 50px;"
- src=@{Photos.getPhoto(item.author.profile.profilePhoto)} />
+ src=@{Photos.getPhoto(item.author.profile.profilePhoto.id)} />
</div>
<div class="individual-post">
2  app/views/Users/about.html
View
@@ -5,7 +5,7 @@
<img src="@{Photos.getPhoto(2)}" height="120" width="120" />
#{/if}
#{else}
- <img src="@{Photos.getPhoto(user.profile.profilePhoto)}" height="120" width="120" />
+ <img src="@{Photos.getPhoto(user.profile.profilePhoto.id)}" height="120" width="120" />
#{/else}
</div>
<div style="clear: both;text-align:center;width: 100%;">
4 app/views/main.html
View
@@ -81,7 +81,7 @@
<div id="friendRequest" onclick="event.stopPropagation()" style="border: thin solid #000000; background-color: #ffffff; z-index: 2; top: 40px; display: none; position:absolute; margin-left: 100px;" >
#{list items:currentUser.requestedFriends(), as:'request'}
<div style="border-bottom: thin solid #000033; color: black; z-index: 3; height: 100px; padding-left: 10px; padding-right: 10px; padding-top: 3px">
- <img style="width:50px; height:50px;" src=@{Photos.getPhoto(request.from.profile.profilePhoto)} />
+ <img style="width:50px; height:50px;" src=@{Photos.getPhoto(request.from.profile.profilePhoto.id)} />
<a style="color: #000099;" href=@{Application.news(request.from.id)}> ${request.from}</a>
<br>
<a style="color: #000099;" href=@{Application.requestFriends(request.from.id)}>Accept</a>
@@ -95,7 +95,7 @@
#{/form}
<div class="account">
<a href="@{Application.account()}">
- <img src="@{Photos.getPhoto(currentUser.profile.profilePhoto)}" height="30" width="30" style="vertical-align:middle;"/> ${currentUser.first_name} ${currentUser.last_name}
+ <img src="@{Photos.getPhoto(currentUser.profile.profilePhoto.id)}" height="30" width="30" style="vertical-align:middle;"/> ${currentUser.first_name} ${currentUser.last_name}
</a>
<a href="@{Application.news()}">Home</a>
<a href="@{Secure.logout()}">Logout</a>
2  app/views/tags/comment.html
View
@@ -2,7 +2,7 @@
style="background-color: #e8e8e8; margin-top: 2px; width: 100%;">
<div class="comment-content">
<div class="comment-thumb">
- <img style="width: 30px; height: 30px;" src="@{Photos.getPhoto(_comment.author.profile.profilePhoto)}" />
+ <img style="width: 30px; height: 30px;" src="@{Photos.getPhoto(_comment.author.profile.profilePhoto.id)}" />
</div>
<div class="comment-author">
<a href="@{Users.about(_comment.author.id)}">${_comment.author.name}</a>
2  app/views/tags/lhsNav.html
View
@@ -5,7 +5,7 @@
<img src="@{Photos.getPhoto(2)}" height="120" width="120" />
#{/if}
#{else}
- <img src="@{Photos.getPhoto(_user.profile.profilePhoto)}" height="120" width="120" />
+ <img src="@{Photos.getPhoto(_user.profile.profilePhoto.id)}" height="120" width="120" />
#{/else}
</div>
<div style="clear: both;text-align:center;width: 100%;">
4 app/views/tags/post.html
View
@@ -2,7 +2,7 @@
<div class="hideable">
<div class="left">
<img style="width: 50px; height: 50px;"
- src="@{Photos.getPhoto(_item.author.profile.profilePhoto)}" />
+ src="@{Photos.getPhoto(_item.author.profile.profilePhoto.id)}" />
</div>
<div class="individual-post">
@@ -62,7 +62,7 @@
<div id="new_comment_for_post${_item.id}" style="clear: both;" >
<img style="width: 30px; height: 30px; vertical-align: top;"
- src=@{Photos.getPhoto(_user.profile.profilePhoto)} display="inline" />
+ src=@{Photos.getPhoto(_user.profile.profilePhoto.id)} display="inline" />
<textarea name="comment_content${_item.id}" id="commentContent${_item.id}"
style="color:grey;" resize="vertical" rows="2" cols="35" maxlength="400" ></textarea>
<a class=button id="commentSubmit${_item.id}" href="#" onclick="return false;">Comment</a>
4 conf/messages
View
@@ -77,7 +77,7 @@ photo.currentProfilePhoto=Current Profile Photo
photo.newPhoto=New Photo
photo.upload=Upload
photo.setProfilePhoto=Set Your Profile Photo
-photo.setAsProfilePhoto=Set as profile photo
-photo.useGravatar=Use Gravatar
+photo.setAsProfilePhoto=Set as Profile Photo
+photo.useGravatar="Use Gravatar"
photo.signUpGravatar=Sign up to use Gravatar
photo.gravatarNote=Note: After signing up, it may take some time for the photo to propagate.
1  conf/routes
View
@@ -43,6 +43,7 @@ GET /photos/? Photos.photos
POST /photos Photos.addPhoto
GET /photos/{<[0-9]+>photoId} Photos.getPhoto
GET /photos/setProfilePhoto Photos.setProfilePhoto
+POST /photos/setProfilePhoto Photos.setProfilePhoto
GET /photos/{<[0-9]+>photoId}/delete Photos.removePhoto
GET /photos/setProfilePhotoPage Photos.setProfilePhotoPage
GET /photos/setProfilePhoto Photos.setProfilePhotoPage
Something went wrong with that request. Please try again.