Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
14 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package us.wearecurio.controller
import grails.gsp.PageRenderer
import org.codehaus.groovy.grails.web.json.JSONObject
import us.wearecurio.model.Discussion
import us.wearecurio.model.InitialLoginConfiguration
import us.wearecurio.model.OAuthAccount
import us.wearecurio.model.Sprint
import us.wearecurio.model.User
import us.wearecurio.model.UserGroup
import us.wearecurio.services.DataService
import us.wearecurio.services.FitBitDataService
import us.wearecurio.services.UserRegistrationService
import us.wearecurio.services.JawboneService
import us.wearecurio.services.MovesDataService
import us.wearecurio.services.OuraDataService
Expand All @@ -26,6 +28,8 @@ class HomeController extends DataController {

static allowedMethods = [notifyJawbone: "POST", notifyfitbit: "POST"]

UserRegistrationService userRegistrationService

TwitterDataService twitterDataService
WithingsDataService withingsDataService
FitBitDataService fitBitDataService
Expand Down Expand Up @@ -520,9 +524,11 @@ class HomeController extends DataController {
}

def index() {
debug "HomeController.index()"
debug "HomeController.index() called with params: $params"
def user = sessionUser()
[prefs:user.getPreferences(), showTime:params.showTime?:0, templateVer:urlService.template(request)]
[ prefs:user.getPreferences(),
showTime:params.showTime?:0, templateVer:urlService.template(request),
initialConfig:userRegistrationService.register(user, params?.promoCode).initialLoginConfig]
}

def load() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package us.wearecurio.controller
import grails.converters.JSON
import org.springframework.http.HttpStatus
//import us.wearecurio.model.InitialLoginConfiguration
import us.wearecurio.model.PasswordRecovery
import us.wearecurio.model.PushNotificationDevice
import us.wearecurio.model.Tag
import us.wearecurio.model.Entry
import us.wearecurio.model.User
import us.wearecurio.model.VerificationStatus
import us.wearecurio.services.EmailService
Expand Down Expand Up @@ -458,9 +461,33 @@ class LoginController extends SessionController {
if (p.metaTagName3 && p.metaTagValue3) {
user.addMetaTag(p.metaTagName3, p.metaTagValue3)
}

// String promo = p.promo_code?.trim()?.toLowerCase()
// InitialLoginConfiguration promoLogin
// if( promo != null && promo != "") {
// promoLogin = InitialLoginConfiguration.findByPromoCode(promo)
// if (promoLogin == null) {
// flash.message = "'$promo' is an invalid promo code"
// } else {
// flash.message = "registered with promo code:'$promo'"
// }
// } else {
// flash.message = "registered without promo code"
// }
// if (promoLogin == null) {
// promoLogin = InitialLoginConfiguration.defaultConfiguration()
// }
// promoLogin.interestTags?.each{user.addInterestTag(Tag.create(it))}
// promoLogin.bookmarks?.each{Entry.createBookmark(user.id,it)}
// params.initialConfig = promoLogin
params.promoCode = p.promo_code?.trim()?.toLowerCase()

setLoginUser(user)
execVerifyUser(user)
retVal['success'] = true
//retVal['initialConfig'] = promoLogin
//params.precontroller = "home"
//params.preaction = "sprint"
return retVal
}
}
Expand All @@ -474,9 +501,10 @@ class LoginController extends SessionController {
return
}
def retVal = execRegister(params)
debug "params: $params"
if (retVal['success']) {
session.showHelp = true
redirect(url:toUrl(controller: params.precontroller ?: 'home', action: params.preaction ?: 'index'))
redirect(url:toUrl(controller: params.precontroller ?: 'home', action: params.preaction ?: 'index', params: params))
} else if (retVal['errorCode'] == REGISTER_ERROR_USER_ALREADY_EXISTS) {
flash.message = "User " + params.username + " already exists"
redirect(url:toUrl(action:"register",
Expand Down
23 changes: 23 additions & 0 deletions grails-app/domain/us/wearecurio/model/Entry.groovy
Original file line number Diff line number Diff line change
Expand Up @@ -616,6 +616,29 @@ class Entry implements Comparable {
return e
}

public static Entry createBookmark(Long userId, String bookmarkText) {
return createBookmark(userId, bookmarkText, new Date())
}

public static Entry createBookmark(Long userId, String bookmarkText, Date baseDate) {
return createBookmark(userId, bookmarkText, baseDate, new EntryStats())
}

public static Entry createBookmark(Long userId, String bookmarkText, Date baseDate, EntryStats stats, EntryParserService entryParserService=null) {
return Entry.create(
userId,
(entryParserService==null?
EntryParserService.get():
entryParserService).parse(
baseDate,
"Etc/UTC",
bookmarkText,
RepeatType.CONTINUOUSGHOST.id,
null,
baseDate),
stats)
}

protected EntryGroup createOrFetchGroup() {
if (group != null) return group

Expand Down
160 changes: 160 additions & 0 deletions grails-app/domain/us/wearecurio/model/InitialLoginConfiguration.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,160 @@
package us.wearecurio.model

import groovy.transform.AutoClone

import us.wearecurio.utility.Utils

class InitialLoginConfiguration {

static final String DEFAULT_PROMO_CODE = "default"

String promoCode
String customQuestion1
String customQuestion2
String trackExample1
String trackExample2
String trackExample3
String trackExample4
String deviceExample
String sampleQuestionDuration
String sampleQuestionDurationExampleAnswers
String sampleQuestionRating
String sampleQuestionRatingRange
String sampleQuestionRatingExampleAnswer1
String sampleQuestionRatingExampleAnswer2
String sampleQuestionRatingExampleAnswer3
String today1
String today1Example
String today2
String today2Example
String today3
String today3Example
String today4
String today4Example

static hasMany = [interestTags: String, bookmarks: String]
List interestTags
List bookmarks

private setDefaults() {
customQuestion1 = "Does caffeine affect my sleep?"
customQuestion2 = "Does exercise really affect my mood?"
trackExample1 = "your <strong><i>mood</i></strong>"
trackExample2 = "how much <strong><i>sleep</i></strong> you get"
trackExample3 = "the <strong><i>coffee</i></strong> you drink"
trackExample4 = "the <strong><i>steps</i></strong> you take"
deviceExample = "the Oura ring (via your user profile)"
sampleQuestionDuration = "How many hours did you sleep last night?"
sampleQuestionDurationExampleAnswers = "e.g. 8 hours 10 minutes or 8hrs 10 mins"
sampleQuestionRating = "How's your mood right now?"
sampleQuestionRatingRange = "a number from 1 to 10"
sampleQuestionRatingExampleAnswer1 = "1 would mean 'Not the best day'"
sampleQuestionRatingExampleAnswer2 = "5 would mean 'Just so-so'"
sampleQuestionRatingExampleAnswer3 = "10 would mean 'Super stoked'"
today1 = "DRINK"
today1Example = "e.g. coffee 1 cup 8am"
today2 = "EXERCISE"
today2Example = "e.g. walk 9500 steps"
today3 = "WORK"
today3Example = "e.g. work 7 hours 30 minutes"
today4 = "SUPPLEMENTS"
today4Example = "e.g. aspirin 400 mg, or vitamin c 200 mg"

interestTags = ["sleep"]
bookmarks = ["sleep 8 hours"]
}

static copy(InitialLoginConfiguration from, InitialLoginConfiguration to) {
to.customQuestion1 = from.customQuestion1
to.customQuestion2 = from.customQuestion2
to.trackExample1 = from.trackExample1
to.trackExample2 = from.trackExample2
to.trackExample3 = from.trackExample3
to.trackExample4 = from.trackExample4
to.deviceExample = from.deviceExample
to.sampleQuestionDuration = from.sampleQuestionDuration
to.sampleQuestionDurationExampleAnswers = from.sampleQuestionDurationExampleAnswers
to.sampleQuestionRating = from.sampleQuestionRating
to.sampleQuestionRatingRange = from.sampleQuestionRatingRange
to.sampleQuestionRatingExampleAnswer1 = from.sampleQuestionRatingExampleAnswer1
to.sampleQuestionRatingExampleAnswer2 = from.sampleQuestionRatingExampleAnswer2
to.sampleQuestionRatingExampleAnswer3 = from.sampleQuestionRatingExampleAnswer3
to.today1 = from.today1
to.today1Example = from.today1Example
to.today2 = from.today2
to.today2Example = from.today2Example
to.today3 = from.today3
to.today3Example = from.today3Example
to.today4 = from.today4
to.today4Example = from.today4Example

to.interestTags = []
from.interestTags.each{ to.interestTags << it }
to.bookmarks = []
from.bookmarks.each{ to.bookmarks << it }
}

static InitialLoginConfiguration defaultConfiguration() {
InitialLoginConfiguration ret = InitialLoginConfiguration.findByPromoCode(DEFAULT_PROMO_CODE)

if (ret == null) {
ret = InitialLoginConfiguration.create()
ret.promoCode = DEFAULT_PROMO_CODE
ret.setDefaults()
Utils.save(ret, true)
}

return ret
}

static InitialLoginConfiguration createFromDefault() {
InitialLoginConfiguration ret = InitialLoginConfiguration.create()
ret.promoCode = ""

InitialLoginConfiguration d = defaultConfiguration()
if (d != null) {
copy(d, ret)
}

return ret
}

static InitialLoginConfiguration createFromDefault(String promoCode, boolean save=false) {
InitialLoginConfiguration ret = createFromDefault()
if (ret != null) {
ret.promoCode = promoCode

if (save) {
Utils.save(ret, true)
}
}

return ret
}

static constraints = {
promoCode(maxSize:32, unique: true, blank:false, nullable:false)
customQuestion1(maxSize:64, unique:false, blank:false, nullable:false)
customQuestion2(maxSize:64, unique:false, blank:false, nullable:false)
trackExample1(maxSize:64, unique:false, blank:false, nullable:false)
trackExample2(maxSize:64, unique:false, blank:false, nullable:false)
trackExample3(maxSize:64, unique:false, blank:false, nullable:false)
trackExample4(maxSize:64, unique:false, blank:false, nullable:false)
deviceExample(maxSize:64, unique:false, blank:false, nullable:false)
sampleQuestionDuration(maxSize:64, unique:false, blank:false, nullable:false)
sampleQuestionDurationExampleAnswers(maxSize:64, unique:false, blank:false, nullable:false)
sampleQuestionRating(maxSize:64, unique:false, blank:false, nullable:false)
sampleQuestionRatingRange(maxSize:64, unique:false, blank:false, nullable:false)
sampleQuestionRatingExampleAnswer1(maxSize:64, unique:false, blank:false, nullable:false)
sampleQuestionRatingExampleAnswer2(maxSize:64, unique:false, blank:false, nullable:false)
sampleQuestionRatingExampleAnswer3(maxSize:64, unique:false, blank:false, nullable:false)
today1(maxSize:32, unique:false, blank:false, nullable:false)
today1Example(maxSize:64, unique:false, blank:false, nullable:false)
today2(maxSize:32, unique:false, blank:false, nullable:false)
today2Example(maxSize:64, unique:false, blank:false, nullable:false)
today3(maxSize:32, unique:false, blank:false, nullable:false)
today3Example(maxSize:64, unique:false, blank:false, nullable:false)
today4(maxSize:32, unique:false, blank:false, nullable:false)
today4Example(maxSize:64, unique:false, blank:false, nullable:false)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package us.wearecurio.services

//import grails.transaction.Transactional

import us.wearecurio.model.InitialLoginConfiguration
import us.wearecurio.model.Entry
import us.wearecurio.model.Tag
import us.wearecurio.model.User

class UserRegistrationService {

static enum PromoCodeLookupResult {
FOUND(0), INVALID(1), UNSPECIFIED(2)

final Integer id

static PromoCodeLookupResult get(int id) {
if (id == 0) return FOUND
else if (id == 1) return INVALID
else return UNSPECIFIED
}

PromoCodeLookupResult(int id) {
this.id = id
}

int getId() {
return id
}
}

static transactional = false

Map register(User user, String promoCode=null) {
String promo = promoCode?.trim()?.toLowerCase()
PromoCodeLookupResult lookupResult
InitialLoginConfiguration loginConfig
if( promo != null && promo != "") {
loginConfig = InitialLoginConfiguration.findByPromoCode(promo)
if (loginConfig == null) {
lookupResult = PromoCodeLookupResult.INVALID
} else {
lookupResult = PromoCodeLookupResult.FOUND
}
} else {
lookupResult = PromoCodeLookupResult.UNSPECIFIED
}

if (loginConfig == null) {
loginConfig = InitialLoginConfiguration.defaultConfiguration()
}
loginConfig.interestTags?.each{user.addInterestTag(Tag.create(it))}
loginConfig.bookmarks?.each{Entry.createBookmark(user.id,it)}

return [
success: true,
initialLoginConfig: loginConfig,
promoCodeLookupResult: lookupResult
]
}
}
Loading