mirror of
https://github.com/GwynethLlewelyn/goswi.git
synced 2026-08-14 09:02:27 +00:00
Fixed profile issues; now profiles can be safely saved. Image upload is NOT supported (and probably will never be)
This commit is contained in:
+48
-43
@@ -24,22 +24,22 @@ import (
|
||||
)
|
||||
|
||||
type UserProfile struct {
|
||||
UserUUID string `form:"useruuid" json:"useruuid"`
|
||||
ProfilePartner string `form:"profilePartner" json:"profilePartner"`
|
||||
ProfileAllowPublish int `form:"profileAllowPublish" json:"profileAllowPublish"`
|
||||
ProfileMaturePublish int `form:"profileMaturePublish" json:"profileMaturePublish"`
|
||||
ProfileURL string `form:"profileURL" json:"profileURL"`
|
||||
ProfileWantToMask int `form:"profileWantToMask" json:"profileWantToMask"`
|
||||
ProfileWantTo []string `form:"profileWantTo[]"`
|
||||
ProfileWantToText string `form:"profileWantToText" json:"profileWantToText"`
|
||||
ProfileSkillsMask int `form:"profileSkillsMask" json:"profileSkillsMask"`
|
||||
ProfileSkills []string `form:"profileSkills[]"`
|
||||
ProfileSkillsText string `form:"profileSkillsText" json:"profileSkillsText"`
|
||||
ProfileLanguages string `form:"profileLanguages" json:"profileLanguages"`
|
||||
ProfileImage string `form:"profileImage" json:"profileImage"`
|
||||
ProfileAboutText string `form:"profileAboutText" json:"profileAboutText"`
|
||||
ProfileFirstImage string `form:"profileFirstImage" json:"profileFirstImage"`
|
||||
ProfileFirstText string `form:"profileFirstText" json:"profileFirstText"`
|
||||
UserUUID string `form:"UserUUID" json:"useruuid"`
|
||||
ProfilePartner string `form:"ProfilePartner" json:"profilePartner"`
|
||||
ProfileAllowPublish int `form:"ProfileAllowPublish" json:"profileAllowPublish"`
|
||||
ProfileMaturePublish int `form:"ProfileMaturePublish" json:"profileMaturePublish"`
|
||||
ProfileURL string `form:"ProfileURL" json:"profileURL"`
|
||||
ProfileWantToMask int `form:"ProfileWantToMask" json:"profileWantToMask"`
|
||||
ProfileWantTo []string `form:"ProfileWantTo[]"`
|
||||
ProfileWantToText string `form:"ProfileWantToText" json:"profileWantToText"`
|
||||
ProfileSkillsMask int `form:"ProfileSkillsMask" json:"profileSkillsMask"`
|
||||
ProfileSkills []string `form:"ProfileSkills[]"`
|
||||
ProfileSkillsText string `form:"ProfileSkillsText" json:"profileSkillsText"`
|
||||
ProfileLanguages string `form:"ProfileLanguages" json:"profileLanguages"`
|
||||
ProfileImage string `form:"ProfileImage" json:"profileImage"`
|
||||
ProfileAboutText string `form:"ProfileAboutText" json:"profileAboutText"`
|
||||
ProfileFirstImage string `form:"ProfileFirstImage" json:"profileFirstImage"`
|
||||
ProfileFirstText string `form:"ProfileFirstText" json:"profileFirstText"`
|
||||
}
|
||||
|
||||
// GetProfile connects to the database, does its magic, and spews out a profile. That's the theory at least.
|
||||
@@ -260,6 +260,11 @@ func saveProfile(c *gin.Context) {
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
if *config["ginMode"] == "debug" {
|
||||
log.Printf("[DEBUG] oneProfile is now %+v\n", oneProfile)
|
||||
}
|
||||
|
||||
// check if we really are who we claim to be
|
||||
if thisUUID != oneProfile.UserUUID {
|
||||
c.HTML(http.StatusUnauthorized, "404.tpl", gin.H{
|
||||
@@ -336,21 +341,19 @@ func saveProfile(c *gin.Context) {
|
||||
if *config["ginMode"] == "debug" {
|
||||
log.Printf("[DEBUG] oneProfile.ProfileWantTo is %v, wantToMask is %d, oneProfile.ProfileSkills is %v, skillsMask is %d\n", oneProfile.ProfileWantTo, wantToMask, oneProfile.ProfileSkills, skillsMask)
|
||||
}
|
||||
/*
|
||||
|
||||
// Update it on database
|
||||
result, err := db.Exec("UPDATE userprofile SET profilePartner = ?, profileAllowPublish = ?, profileMaturePublish = ?, profileURL = ?, profileWantToMask = ?, profileWantToText = ?, profileSkillsMask = ?, profileSkillsText = ?, profileLanguages = ?, profileImage = ?, profileAboutText = ?, profileFirstImage = ?, profileFirstText = ? WHERE useruuid = ?"),
|
||||
oneProfile.ProfilePartner,
|
||||
result, err := db.Exec("UPDATE userprofile SET profileAllowPublish = ?, profileMaturePublish = ?, profileURL = ?, profileWantToMask = ?, profileWantToText = ?, profileSkillsMask = ?, profileSkillsText = ?, profileLanguages = ?, profileAboutText = ?, profileFirstText = ? WHERE useruuid = ?",
|
||||
// oneProfile.ProfilePartner,
|
||||
oneProfile.ProfileAllowPublish,
|
||||
oneProfile.ProfileMaturePublish,
|
||||
oneProfile.ProfileURL,
|
||||
wantToMask, // oneProfile.ProfileWantToMask,
|
||||
wantToMask, // oneProfile.ProfileWantToMask, // images are read-only!
|
||||
oneProfile.ProfileWantToText,
|
||||
skillsMask, // oneProfile.ProfileSkillsMask,
|
||||
oneProfile.ProfileSkillsText,
|
||||
oneProfile.ProfileLanguages,
|
||||
oneProfile.ProfileImage,
|
||||
oneProfile.ProfileAboutText,
|
||||
oneProfile.ProfileFirstImage,
|
||||
oneProfile.ProfileFirstText,
|
||||
oneProfile.UserUUID,
|
||||
)
|
||||
@@ -358,28 +361,30 @@ func saveProfile(c *gin.Context) {
|
||||
checkErr(err)
|
||||
|
||||
if numRowsAffected, err := result.RowsAffected(); err != nil {
|
||||
log.Printf("[ERROR] Updating database with new profile for %q failed, error was %q\n", thisUUID, err)
|
||||
} else if *config["ginMode"] == "debug" {
|
||||
log.Printf("[INFO] Success updating database with new profile for %q, number of rows affected: %d\n", thisUUID, numRowsAffected)
|
||||
}
|
||||
*/
|
||||
c.HTML(http.StatusOK, "404.tpl", gin.H{
|
||||
"errorcode" : http.StatusOK,
|
||||
"errortext" : "Saving profile succeeded",
|
||||
"errorbody" : "But... we still haven't done the coding!... So nothing actually happened",
|
||||
"now" : formatAsYear(time.Now()),
|
||||
"author" : *config["author"],
|
||||
"description" : *config["description"],
|
||||
"logo" : *config["logo"],
|
||||
"logoTitle" : *config["logoTitle"],
|
||||
"sidebarCollapsed" : *config["sidebarCollapsed"],
|
||||
"titleCommon" : *config["titleCommon"] + " - Profile",
|
||||
"Username" : session.Get("Username"),
|
||||
"Libravatar" : session.Get("Libravatar"),
|
||||
})
|
||||
log.Println("[INFO] Got form data for profile but code isn't implemented yet")
|
||||
c.HTML(http.StatusOK, "404.tpl", gin.H{
|
||||
"errorcode" : http.StatusOK,
|
||||
"errortext" : "Saving profile failed",
|
||||
"errorbody" : fmt.Sprintf("Database error was: %q [%d row(s) affected]", err, numRowsAffected),
|
||||
"now" : formatAsYear(time.Now()),
|
||||
"author" : *config["author"],
|
||||
"description" : *config["description"],
|
||||
"logo" : *config["logo"],
|
||||
"logoTitle" : *config["logoTitle"],
|
||||
"sidebarCollapsed" : *config["sidebarCollapsed"],
|
||||
"titleCommon" : *config["titleCommon"] + " - Profile",
|
||||
"Username" : session.Get("Username"),
|
||||
"Libravatar" : session.Get("Libravatar"),
|
||||
})
|
||||
|
||||
return
|
||||
log.Printf("[ERROR] Updating database with new profile for %q failed, error was %s\n", thisUUID, err)
|
||||
// TODO(gwyneth): we
|
||||
return
|
||||
} else {
|
||||
if *config["ginMode"] == "debug" {
|
||||
log.Printf("[INFO] Success updating database with new profile for %q, number of rows affected: %d\n", thisUUID, numRowsAffected)
|
||||
}
|
||||
c.Redirect(http.StatusSeeOther, "/user/profile")
|
||||
}
|
||||
}
|
||||
|
||||
// Transformation functions
|
||||
|
||||
+20
-19
@@ -20,23 +20,23 @@
|
||||
<legend class="text-center"><h2>{{- if .Username -}}{{- .Username -}}'s{{- else -}}Your{{- end -}} Profile</h2></legend><br />
|
||||
<!-- About -->
|
||||
<div class="form-group">
|
||||
<label for="AboutText" id="labelAboutText" class="control-label">About you</label>
|
||||
<label for="ProfileAboutText" id="labelAboutText" class="control-label">About you</label>
|
||||
<div class="input-group">
|
||||
<div class="image pr-2">
|
||||
<!-- this will be the user's mugshot -->
|
||||
{{ if .ProfileURL}}
|
||||
<a href="{{- .ProfileURL -}}" target="_blank">
|
||||
{{ end -}}
|
||||
{{ end -}}
|
||||
{{- if .ProfileImage }}
|
||||
<img class="rounded shadow" src="{{- .ProfileImage -}}" alt="{{- .Username }} ({{- .UserUUID -}})" height="256" width="256" srcset="{{- .ProfileImage }} 1x, {{ .ProfileRetinaImage }} 2x">
|
||||
{{ else }}
|
||||
<img class="rounded shadow" src="{{- .Libravatar -}}" alt="{{ .Username }} ({{- .UserUUID -}}" height="256" width="256">
|
||||
{{ end -}}
|
||||
{{- if .ProfileURL}}
|
||||
{{- if .ProfileURL}}
|
||||
</a>
|
||||
{{ end }}
|
||||
</div>
|
||||
<textarea class="form-control" id="AboutText" rows="10" aria-describedby="labelAboutText">{{- .ProfileAboutText -}}</textarea>
|
||||
<textarea class="form-control" id="ProfileAboutText" name="ProfileAboutText" rows="10" aria-describedby="labelAboutText">{{- .ProfileAboutText -}}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
<!-- ProfileURL -->
|
||||
@@ -80,37 +80,37 @@
|
||||
<div class="form-row">
|
||||
<div class="form-group col-3 mt-2 mb-2" id="WantToLeft">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="profileWantTo[]" value="Build" id="WantToBuild" {{ if (bitTest .ProfileWantToMask 1) -}}checked{{- end -}}>
|
||||
<input class="form-check-input" type="checkbox" name="ProfileWantTo[]" value="Build" id="WantToBuild" {{ if (bitTest .ProfileWantToMask 1) -}}checked{{- end -}}>
|
||||
<label class="form-check-label" for="WantToBuild">Build</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="profileWantTo[]" value="Meet" id="WantToMeet" {{ if (bitTest .ProfileWantToMask 4) -}}checked{{- end -}}>
|
||||
<input class="form-check-input" type="checkbox" name="ProfileWantTo[]" value="Meet" id="WantToMeet" {{ if (bitTest .ProfileWantToMask 4) -}}checked{{- end -}}>
|
||||
<label class="form-check-label" for="WantToMeet">Meet</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="profileWantTo[]" value="Group" id="WantToGroup" {{ if (bitTest .ProfileWantToMask 8) -}}checked{{- end -}}>
|
||||
<input class="form-check-input" type="checkbox" name="ProfileWantTo[]" value="Group" id="WantToGroup" {{ if (bitTest .ProfileWantToMask 8) -}}checked{{- end -}}>
|
||||
<label class="form-check-label" for="WantToMeet">Group</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="profileWantTo[]" value="Sell" id="WantToSell" {{ if (bitTest .ProfileWantToMask 32) -}}checked{{- end -}}>
|
||||
<input class="form-check-input" type="checkbox" name="ProfileWantTo[]" value="Sell" id="WantToSell" {{ if (bitTest .ProfileWantToMask 32) -}}checked{{- end -}}>
|
||||
<label class="form-check-label" for="WantToSell">Sell</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-3 mt-2 mb-2" id="WantToRight">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="profileWantTo[]" value="Explore" id="WantToExplore" {{ if (bitTest .ProfileWantToMask 2) -}}checked{{- end -}}>
|
||||
<input class="form-check-input" type="checkbox" name="ProfileWantTo[]" value="Explore" id="WantToExplore" {{ if (bitTest .ProfileWantToMask 2) -}}checked{{- end -}}>
|
||||
<label class="form-check-label" for="WantToExplore">Explore</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="profileWantTo[]" value="BeHired" id="WantToBeHired" {{ if (bitTest .ProfileWantToMask 64) -}}checked{{- end -}}>
|
||||
<input class="form-check-input" type="checkbox" name="ProfileWantTo[]" value="BeHired" id="WantToBeHired" {{ if (bitTest .ProfileWantToMask 64) -}}checked{{- end -}}>
|
||||
<label class="form-check-label" for="WantToBeHired">Be Hired</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="profileWantTo[]" value="Buy" id="WantToBuy" {{ if (bitTest .ProfileWantToMask 16) -}}checked{{- end -}}>
|
||||
<input class="form-check-input" type="checkbox" name="ProfileWantTo[]" value="Buy" id="WantToBuy" {{ if (bitTest .ProfileWantToMask 16) -}}checked{{- end -}}>
|
||||
<label class="form-check-label" for="WantToBuy">Buy</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="profileWantTo[]" value="Hire" id="WantToHire" {{ if (bitTest .ProfileWantToMask 128) -}}checked{{- end -}}>
|
||||
<input class="form-check-input" type="checkbox" name="ProfileWantTo[]" value="Hire" id="WantToHire" {{ if (bitTest .ProfileWantToMask 128) -}}checked{{- end -}}>
|
||||
<label class="form-check-label" for="WantToHire">Hire</label>
|
||||
</div>
|
||||
</div>
|
||||
@@ -131,29 +131,29 @@
|
||||
<div class="form-row">
|
||||
<div class="form-group col-3 mt-2 mb-2" id="SkillsLeft">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="profileSkills[]" value="Textures" id="SkillsTextures" {{ if (bitTest .ProfileSkillsMask 1) -}}checked{{- end -}}>
|
||||
<input class="form-check-input" type="checkbox" name="ProfileSkills[]" value="Textures" id="SkillsTextures" {{ if (bitTest .ProfileSkillsMask 1) -}}checked{{- end -}}>
|
||||
<label class="form-check-label" for="SkillsTextures">Textures</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="profileSkills[]" value="Modeling" id="SkillsModeling" {{ if (bitTest .ProfileSkillsMask 8) -}}checked{{- end -}}>
|
||||
<input class="form-check-input" type="checkbox" name="ProfileSkills[]" value="Modeling" id="SkillsModeling" {{ if (bitTest .ProfileSkillsMask 8) -}}checked{{- end -}}>
|
||||
<label class="form-check-label" for="SkillsModeling">Modeling</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="profileSkills[]" value="Scripting" id="SkillsScripting" {{ if (bitTest .ProfileSkillsMask 16) -}}checked{{- end -}}>
|
||||
<input class="form-check-input" type="checkbox" name="ProfileSkills[]" value="Scripting" id="SkillsScripting" {{ if (bitTest .ProfileSkillsMask 16) -}}checked{{- end -}}>
|
||||
<label class="form-check-label" for="SkillsScripting">Scripting</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="form-group col-3 mt-2 mb-2" id="SkillsRight">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="profileSkills[]" value="Architecture" id="SkillsArchitecture" {{ if (bitTest .ProfileSkillsMask 2) -}}checked{{- end -}}>
|
||||
<input class="form-check-input" type="checkbox" name="ProfileSkills[]" value="Architecture" id="SkillsArchitecture" {{ if (bitTest .ProfileSkillsMask 2) -}}checked{{- end -}}>
|
||||
<label class="form-check-label" for="SkillsArchitecture">Architecture</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="profileSkills[]" value="EventPlanning" id="SkillsEventPlanning" {{ if (bitTest .ProfileSkillsMask 4) -}}checked{{- end -}}>
|
||||
<input class="form-check-input" type="checkbox" name="ProfileSkills[]" value="EventPlanning" id="SkillsEventPlanning" {{ if (bitTest .ProfileSkillsMask 4) -}}checked{{- end -}}>
|
||||
<label class="form-check-label" for="SkillsEventPlanning">Event Planning</label>
|
||||
</div>
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="profileSkills[]" value="CustomCharacters" id="SkillsCustomCharacters" {{ if (bitTest .ProfileSkillsMask 32) -}}checked{{- end -}}>
|
||||
<input class="form-check-input" type="checkbox" name="ProfileSkills[]" value="CustomCharacters" id="SkillsCustomCharacters" {{ if (bitTest .ProfileSkillsMask 32) -}}checked{{- end -}}>
|
||||
<label class="form-check-label" for="SkillsCustomCharacters">Custom Characters</label>
|
||||
</div>
|
||||
</div>
|
||||
@@ -190,7 +190,7 @@
|
||||
<img class="rounded shadow-sm" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVR42mOMa1zzHwAFXAKM3m3GvQAAAABJRU5ErkJggg==" alt="No image for {{- .Username -}}" height="128" width="128">
|
||||
{{- end }}
|
||||
</div>
|
||||
<textarea class="form-control" id="ProfileFirstText" rows="3" aria-describedby="labelProfileFirstText">{{- .ProfileFirstText -}}</textarea>
|
||||
<textarea class="form-control" id="ProfileFirstText" name="ProfileFirstText" rows="3" aria-describedby="labelProfileFirstText">{{- .ProfileFirstText -}}</textarea>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -201,6 +201,7 @@
|
||||
<button type="submit" class="btn btn-primary shadow-sm" value="Submit">Submit <i class="fas fa-paper-plane"></i></button>
|
||||
</div>
|
||||
</fieldset>
|
||||
<input id="UserUUID" name="UserUUID" type="hidden" value="{{- .UserUUID -}}">
|
||||
</form>
|
||||
{{- if .ProfileData }}
|
||||
<div class="invisible">Raw data: {{- .ProfileData -}}</div>
|
||||
|
||||
Reference in New Issue
Block a user