From 212e71a1b9fa999f5eda8737dcb3077d3694962c Mon Sep 17 00:00:00 2001 From: Sarah Jamie Lewis Date: Fri, 17 Dec 2021 17:06:54 -0800 Subject: [PATCH] ChangePassword APIs --- lib.go | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/lib.go b/lib.go index 26d1a0e..b2618b3 100644 --- a/lib.go +++ b/lib.go @@ -13,6 +13,9 @@ import ( constants2 "cwtch.im/cwtch/model/constants" + "git.openprivacy.ca/cwtch.im/libcwtch-go/features" + + // Import SQL Cipher "os/user" "runtime" @@ -882,6 +885,28 @@ func SetMessageAttribute(profileOnion string, conversationID int, channelID int, } } +//export c_ChangePassword +func c_ChangePassword(profile_ptr *C.char, profile_len C.int, oldpassword_ptr *C.char, oldpassword_len C.int, newpassword_ptr *C.char, newpassword_len C.int, newpassword_again_ptr *C.char, newpassword_again_len C.int) { + profileOnion := C.GoStringN(profile_ptr, profile_len) + oldPassword := C.GoStringN(oldpassword_ptr, oldpassword_len) + newPassword := C.GoStringN(newpassword_ptr, newpassword_len) + newPasswordAgain := C.GoStringN(newpassword_again_ptr, newpassword_again_len) + ChangePassword(profileOnion, oldPassword, newPassword, newPasswordAgain) +} + +// ChangePassword provides a wrapper around profile.ChangePassword +func ChangePassword(profileOnion string, oldPassword string, newPassword string, newPasswordAgain string) { + profile := application.GetPeer(profileOnion) + log.Infof("changing password for %v", profileOnion) + err := profile.ChangePassword(oldPassword, newPassword, newPasswordAgain) + log.Infof("change password result %v", err) + if err == nil { + eventHandler.Push(event.NewEvent(event.AppError, map[event.Field]string{event.Data: features.ConstructResponse("changepassword", constants.StatusSuccess).Error()})) + } else { + eventHandler.Push(event.NewEvent(event.AppError, map[event.Field]string{event.Data: features.ConstructResponse("changepassword", err.Error()).Error()})) + } +} + //export c_ShutdownCwtch func c_ShutdownCwtch() { ShutdownCwtch()