-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/main' into docs
- Loading branch information
Showing
7 changed files
with
162 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Code Of Conduct | ||
|
||
## Our Pledge | ||
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to make participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. | ||
|
||
## Our Standards | ||
Examples of behaviour that contributes to a positive environment for our community include: | ||
|
||
* Demonstrating empathy and kindness toward other people | ||
* Being respectful of differing opinions, viewpoints, and experiences | ||
* Giving and gracefully accepting constructive feedback | ||
* Accepting responsibility and apologising to those affected by our mistakes, and learning from the experience | ||
* Focusing on what is best not just for us as individuals, but for the overall community | ||
Examples of unacceptable behaviour include: | ||
|
||
* The use of sexualised language or imagery, and sexual attention or advances | ||
* Trolling, insulting or derogatory comments, and personal or political attacks | ||
* Public or private harassment | ||
* Publishing others' private information, such as a physical or email address, without their explicit permission | ||
* Other conduct which could reasonably be considered inappropriate in a professional setting | ||
## Our Responsibilities | ||
Project maintainers are responsible for clarifying and enforcing our standards of acceptable behaviour and will take appropriate and fair corrective action in response to any instances of unacceptable behaviour. | ||
|
||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviours that they deem inappropriate, threatening, offensive, or harmful. | ||
|
||
## Scope | ||
This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. | ||
|
||
|
||
## Enforcement | ||
Instances of abusive, harassing, or otherwise unacceptable behaviour may be reported to the community leaders responsible for enforcement at <[email protected].>. All complaints will be reviewed and investigated promptly and fairly. | ||
## Attribution | ||
This Code of Conduct is adapted from the Contributor Covenant, version 1.4, available at http://contributor-covenant.org/version/1/4 | ||
|
||
|
||
Attribution | ||
This Code of Conduct is adapted from the Contributor Covenant, version 1.4, available at http://contributor-covenant.org/version/1/4 |
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,86 @@ | ||
package controllers | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/kossiitkgp/kwoc-backend/v2/middleware" | ||
"github.com/kossiitkgp/kwoc-backend/v2/utils" | ||
"gorm.io/gorm" | ||
|
||
"github.com/kossiitkgp/kwoc-backend/v2/models" | ||
) | ||
|
||
type ProfileResBodyFields struct { | ||
Username string `json:"username"` | ||
Name string `json:"name"` | ||
Email string `json:"email"` | ||
// `mentor` or `student` | ||
Type string `json:"type"` | ||
} | ||
|
||
// FetchProfile godoc | ||
// @Summary Fetches user profile | ||
// @Description Fetches the user's profile from the JWT, if it is valid. If invalid, returns an error. | ||
// @Accept plain | ||
// @Produce json | ||
// @Success 200 {object} ProfileResBodyFields "Succesfully authenticated." | ||
// @Failure 400 {object} utils.HTTPMessage "User is not registered." | ||
// @Failure 401 {object} utils.HTTPMessage "JWT session token invalid." | ||
// @Failure 500 {object} utils.HTTPMessage "Error parsing JWT string." | ||
// | ||
// @Security JWT | ||
// | ||
// @Router /profile [get] | ||
func FetchProfile(w http.ResponseWriter, r *http.Request) { | ||
app := r.Context().Value(middleware.APP_CTX_KEY).(*middleware.App) | ||
db := app.Db | ||
|
||
username := r.Context().Value(middleware.LOGIN_CTX_USERNAME_KEY).(string) | ||
|
||
// Check if the student already exists in the db | ||
student := models.Student{} | ||
tx := db. | ||
Table("students"). | ||
Where("username = ?", username). | ||
First(&student) | ||
|
||
if tx.Error != nil && tx.Error != gorm.ErrRecordNotFound { | ||
utils.LogErrAndRespond(r, w, tx.Error, "Database error.", http.StatusInternalServerError) | ||
return | ||
} | ||
|
||
student_exists := student.Username == username | ||
if student_exists { | ||
utils.RespondWithJson(r, w, ProfileResBodyFields{ | ||
Username: student.Username, | ||
Name: student.Name, | ||
Email: student.Email, | ||
Type: "student", | ||
}) | ||
return | ||
} | ||
|
||
// Check if a mentor of the same username exists | ||
mentor := models.Mentor{} | ||
tx = db. | ||
Table("mentors"). | ||
Where("username = ?", username). | ||
First(&mentor) | ||
if tx.Error != nil && tx.Error != gorm.ErrRecordNotFound { | ||
utils.LogErrAndRespond(r, w, tx.Error, "Database error.", http.StatusInternalServerError) | ||
return | ||
} | ||
mentor_exists := mentor.Username == username | ||
|
||
if mentor_exists { | ||
utils.RespondWithJson(r, w, ProfileResBodyFields{ | ||
Username: mentor.Username, | ||
Name: mentor.Name, | ||
Email: mentor.Email, | ||
Type: "mentor", | ||
}) | ||
return | ||
} | ||
|
||
utils.RespondWithHTTPMessage(r, w, http.StatusBadRequest, "User is not registered.") | ||
} |
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
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