-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fcc8331
commit 67b081a
Showing
13 changed files
with
314 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
grails-app/controllers/com/expensetracker/Settings/SettingsController.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,86 @@ | ||
package com.expensetracker.Settings | ||
|
||
import com.expensetracker.Profile.Profile | ||
import com.expensetracker.SpringSecurity.SecUser | ||
import grails.plugin.springsecurity.annotation.Secured | ||
|
||
import com.expensetracker.Learn.Learn | ||
|
||
class SettingsController { | ||
|
||
def springSecurityService | ||
|
||
@Secured(['ROLE_USER']) | ||
def index() { } | ||
|
||
def savelearn(String newWord, String newMeaning) { | ||
|
||
println params | ||
def userId = SecUser.get(springSecurityService.currentUser.id) | ||
def search = Learn.findByWord(newWord) | ||
|
||
if(search){ | ||
Learn learnInstance = Learn.get(search.id) | ||
learnInstance.count++ | ||
redirect(action: 'learn') | ||
} else { | ||
Learn learnInstance = new Learn(word: newWord, meaning: newMeaning, count: 0L, author: userId) | ||
learnInstance.save() | ||
redirect(action:'learn') | ||
|
||
} | ||
} | ||
|
||
def learn() {} | ||
|
||
def password() {} | ||
|
||
def changePassword(String current_password, String new_password, String confirm_password) { | ||
|
||
println params | ||
SecUser activeUser = springSecurityService.currentUser | ||
def password_old = current_password | ||
if(!springSecurityService.passwordEncoder.isPasswordValid(activeUser.getPassword(), password_old, null)) { | ||
render "incorrect" | ||
|
||
}else { | ||
SecUser changePassword = SecUser.get(springSecurityService.currentUser.id) | ||
changePassword.password = new_password | ||
render "password changed successfully" | ||
} | ||
} | ||
|
||
def profile() { | ||
|
||
def currentUser = SecUser.get(springSecurityService.currentUser.id) | ||
Profile viewProfileInstance = Profile.findByEmail(currentUser) | ||
println viewProfileInstance | ||
render(view: 'profile', model:[profileDetails: viewProfileInstance]) | ||
} | ||
|
||
def saveUpdated(String fullname, String username, String gender, Long contact) { | ||
|
||
def genderStatus | ||
|
||
Profile profileInstance = Profile.findByEmail(SecUser.get(springSecurityService.currentUser.id)) | ||
profileInstance.userName = username | ||
profileInstance.contactNumber = contact | ||
profileInstance.fullName = fullname | ||
|
||
if(gender == 'Male') { | ||
genderStatus = Profile.Gender.MALE | ||
} else { | ||
genderStatus = Profile.Gender.FEMALE | ||
} | ||
|
||
profileInstance.gender = genderStatus | ||
|
||
profileInstance.save() | ||
redirect(controller:'settings', action: 'profile') | ||
} | ||
|
||
def updateProfile() { | ||
|
||
[edited: Profile.findByEmail(SecUser.get(springSecurityService.currentUser.id))] | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
grails-app/domain/com/expensetracker/Expense/Expense.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,27 @@ | ||
package com.expensetracker.Expense | ||
|
||
import com.expensetracker.SpringSecurity.SecUser | ||
|
||
class Expense { | ||
|
||
Long transactionAmount | ||
String transactionPurpose | ||
Date dateCreated | ||
Date lastUpdated | ||
SecUser author | ||
TransactionType transactionType | ||
|
||
static constraints = { | ||
transactionAmount min: 0l, matches:"[0-9]+",blank:false | ||
transactionPurpose blank: false, nullable:false | ||
} | ||
|
||
enum TransactionType{ | ||
DEBIT(1),CREDIT(2) | ||
final int id | ||
|
||
TransactionType(int id) { | ||
this.id = id | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
package com.expensetracker.Learn | ||
|
||
import com.expensetracker.SpringSecurity.SecUser | ||
|
||
class Learn { | ||
|
||
String word | ||
String meaning | ||
Long count | ||
SecUser author | ||
|
||
static constraints = { | ||
word blank: false, nullable: false | ||
meaning blank: false, nullable: false | ||
count min: 1L | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head></head> | ||
<body> | ||
<g:link controller="settings" action="learn">Learn</g:link><br> | ||
<g:link controller="settings" action="profile">Profile</g:link><br> | ||
<g:link controller="settings" action="password">Change Password</g:link> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
<g:form controller="settings" action="savelearn" method="post"> | ||
<g:textField name="newWord"/> | ||
<g:textField name="newMeaning"/> | ||
<g:submitButton name="save" value="save"/> | ||
</g:form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<html> | ||
<head></head> | ||
<body> | ||
<g:form controller="settings" action="changePassword" method="post"> | ||
<g:passwordField name="current_password"/> | ||
<g:passwordField name="new_password"/> | ||
<g:passwordField name="confirm_password"/> | ||
<g:submitButton name="save" value="save"/> | ||
</g:form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
<html> | ||
<head></head> | ||
<body> | ||
<g:if test="${profileDetails}"> | ||
<p>Full Name: ${profileDetails.fullName}</p> | ||
<p>User Name: ${profileDetails.userName}</p> | ||
<p>Gender: ${profileDetails.gender}</p> | ||
<p>Contact: ${profileDetails.contactNumber}</p> | ||
<p>Email: ${profileDetails.email.username}</p> | ||
<p>Wallet Amount: ${profileDetails.walletAmount}</p> | ||
<g:link controller="settings" action="updateProfile">Edit</g:link> | ||
</g:if> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<html> | ||
<head> | ||
</head> | ||
<body> | ||
<g:form controller="settings" action="saveUpdated"> | ||
<g:textField name="fullname" value="${edited.fullName}"/> | ||
<g:textField name="username" value="${edited.userName}"/> | ||
<g:textField name="contact" value="${edited.contactNumber}"/> | ||
<select class="form-control" name="gender" id="gender" required="required"> | ||
<option disabled selected value="">--Select a status--</option> | ||
<option value="Male">Male</option> | ||
<option value="Female">Female</option> | ||
</select> | ||
<g:submitButton name="save" value="save"/> | ||
</g:form> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.