Skip to content

Commit

Permalink
wax & wings. fix for whatsapp login
Browse files Browse the repository at this point in the history
  • Loading branch information
edospadoni committed Jan 21, 2025
1 parent 4dbbad4 commit cd6050c
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 7 deletions.
11 changes: 10 additions & 1 deletion wax/methods/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func GetDaemonTemporary(c *gin.Context) {
skipVerification := utils.GetHotspotPreferencesByKey(unit.HotspotId, "email_login_skip_auth")

// create user auth
if skipVerification.Value == "true" {
if skipVerification.Value == "true" && username != "whatsapp" {
// convert userId to int
userIdInt, _ := strconv.Atoi(userId)

Expand All @@ -133,6 +133,10 @@ func GetDaemonTemporary(c *gin.Context) {
// set credentials
utils.CreateUserAuth(sessionId, 0, unitUuid, 0, username+":"+mac, password, "login")
} else {
// handle whatsapp case
if username == "whatsapp" {
username = username + ":" + sessionId
}
utils.CreateUserAuth(sessionId, secondsInt, unitUuid, 0, username, "", "temporary")
}

Expand All @@ -154,6 +158,11 @@ func GetDaemonLogout(c *gin.Context) {
unitUuid := c.Query("uuid")
username := c.Query("username")

// handle whatsapp case
if username == "whatsapp" {
username = username + ":" + sessionId
}

// create user auth
utils.CreateUserAuth(sessionId, 0, unitUuid, 0, username, "", "logout")

Expand Down
7 changes: 7 additions & 0 deletions wax/methods/auth_social.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ type WhatsappPOST struct {
AccountSid string `form:"AccountSid"`
From string `form:"From"`
ApiVersion string `form:"ApiVersion"`
MessageType string `form:"MessageType"`
}

func WhatsappAuth(c *gin.Context) {
Expand Down Expand Up @@ -191,6 +192,9 @@ func WhatsappAuth(c *gin.Context) {
// create marketing info with user infos
utils.CreateUserMarketing(newUser.Id, smsMarketingData{Number: number}, "whatsapp")

// create user auth
utils.CreateUserAuth(sessionId, 0, uuid, newUser.Id, newUser.Username, newUser.Password, "created")

// response to client
c.JSON(http.StatusOK, gin.H{"user_id": number, "user_db_id": newUser.Id})
} else {
Expand Down Expand Up @@ -254,6 +258,9 @@ func WhatsappAuth(c *gin.Context) {
db := database.Instance()
db.Save(&user)

// create user auth
utils.CreateUserAuth(sessionId, 0, uuid, user.Id, user.Username, user.Password, "updated")

// response to client
c.JSON(http.StatusOK, gin.H{"user_id": number, "exists": true, "user_db_id": user.Id})
}
Expand Down
10 changes: 10 additions & 0 deletions wax/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -991,11 +991,21 @@ func CreateUserAuth(sessionId string, sessionTimeout int, unitUuid string, userI
Type: typeAuth,
Updated: time.Now().UTC(),
}

// delete whatsapp "logout" record
var whatsappLogout models.DaemonAuth
db.Where("session_id = ? AND unit_uuid = ? AND username = ? AND type = 'logout'", sessionId, unitUuid, "whatsapp"+":"+sessionId).First(&whatsappLogout)
db.Delete(&whatsappLogout)
} else {
// update record
daemonAuth.Password = password
daemonAuth.Type = typeAuth
daemonAuth.Updated = time.Now().UTC()

// delete whatsapp "logout" record
var whatsappLogout models.DaemonAuth
db.Where("session_id = ? AND unit_uuid = ? AND username = ? AND type = 'logout'", sessionId, unitUuid, "whatsapp"+":"+sessionId).First(&whatsappLogout)
db.Delete(&whatsappLogout)
}

// save record
Expand Down
2 changes: 1 addition & 1 deletion wings/src/components/LoginPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
>
<h3 :style="textStyle">{{ $t("login.choose_login") }}</h3>
<div class="ui relaxed list">
<div v-if="hotspot.preferences.whatsapp_login == 'true' && isMobile" class="item">
<div v-if="hotspot.preferences.whatsapp_login == 'true'" class="item">
<div @click="changeRoute('/login/whatsapp', false)" class="ui green button big fluid">
<i class="whatsapp icon"></i>
{{ $t("login.with_whatsapp") }}
Expand Down
13 changes: 8 additions & 5 deletions wings/src/components/social/WhatsappPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -225,25 +225,25 @@ export default {
this.codeRequested = true;
}
},
redirectAuth() {
redirectAuth(shortCode) {
window.location.replace(
"http://wa.me/" +
CONFIG.WHATSAPP_NUMBER.replace("+", "") +
"?text=login " +
encodeURIComponent(this.shortCode)
encodeURIComponent(shortCode || this.shortCode)
);
},
getCode: function(reset) {
var params = this.extractParams();
// open temp session for the user
this.doTempSession(
null,
"whatsapp",
this.userId,
"true",
function(responseTmp) {
// if apple
if (this.iOS) {
/*if (this.iOS) {
var origin = "http://conncheck." + window.location.host;
var pathname = window.location.pathname;
var query =
Expand All @@ -266,7 +266,8 @@ export default {
} else {
this.openBtn = true;
this.shortCode = responseTmp.body.short_code;
}
}*/
this.redirectAuth(responseTmp.body.short_code);
},
function(error) {
this.codeRequested = false;
Expand Down Expand Up @@ -318,6 +319,7 @@ export default {
var pathname = window.location.pathname;
this.doDedaloLogout(
"whatsapp",
function(responseDedaloLogout) {
window.location.replace(redirectUrl + pathname + query);
},
Expand All @@ -330,6 +332,7 @@ export default {
} else {
// exec logout
this.doDedaloLogout(
"whatsapp",
function(responseDedaloLogout) {
// exec dedalo login
this.doDedaloLogin(
Expand Down

0 comments on commit cd6050c

Please sign in to comment.