Exemplo n.º 1
0
func UpdateUserName(w http.ResponseWriter, r *http.Request) {
	phoneNumber := r.Header.Get("phone_number")
	updateUserName := requests.UpdateUserName{}
	service.DecodeJson(&updateUserName, r.Body)
	userName := updateUserName.UserName
	table := "users"
	field := fmt.Sprintf("user_name='%s'", userName)
	condition := fmt.Sprintf("phone_number = '%s'", phoneNumber)
	statusUpdate, messageUpdate := service.UpdateQuery(table, field, condition)
	w.WriteHeader(statusUpdate)
	printResult(w, statusUpdate, messageUpdate, requests.UserUpdateType{userName, phoneNumber})
}
Exemplo n.º 2
0
func UpdatePhoneNumber(w http.ResponseWriter, r *http.Request) {
	phoneNumber := r.Header.Get("phone_number")
	userTokenJson := requests.PhoneNumberJson{}
	service.DecodeJson(&userTokenJson, r.Body)
	newphoneNumber := userTokenJson.PhoneNumber
	if phoneNumber == "" {
		w.WriteHeader(400)
		routes.ServeJson(w, service.GetErrorMessageType(400, "data empty"))
	} else {
		resultHashed := hashedMobileNumber(phoneNumber)
		field := fmt.Sprintf("phone_number = '%s', token = '%s'", newphoneNumber, resultHashed)
		condition := fmt.Sprintf("phone_number = '%s'", phoneNumber)
		statusUpdate, messageUpdate := service.UpdateQuery("users", field, condition)
		userToken := requests.UserToken{newphoneNumber, resultHashed}
		printResult(w, statusUpdate, messageUpdate, userToken)
	}
}
Exemplo n.º 3
0
func GetUsers(w http.ResponseWriter, r *http.Request) {
	phoneNumber := r.Header.Get("mobile_phone")
	contactListJson := requests.ContactList{}
	service.DecodeJson(&contactListJson, r.Body)
	contacts := contactListJson.Contact
	if len(contacts) > service.ReqContactsTreshold {
		return
	}
	chanContactString := mapContactListJson(contacts)
	contact := <-chanContactString
	close(chanContactString)

	condition := fmt.Sprintf("phone_number IN (%s) AND phone_number NOT IN "+
		" (SELECT friend_phone_number FROM users u JOIN friends_relationship fr "+
		" ON u.`phone_number` = fr.`user_phone_number` WHERE u.`phone_number` = '%s' )", contact, phoneNumber)
	sequel := selectUserSQL(condition)
	resultSelectUserSQL(w, sequel)
}
Exemplo n.º 4
0
func GenerateNewToken(w http.ResponseWriter, r *http.Request) {
	userId := 0
	userTokenJson := requests.PhoneNumberJson{}
	service.DecodeJson(&userTokenJson, r.Body)

	sqlRow, err := service.ExecuteChannelSqlRow(getUserIdSQL(userTokenJson.PhoneNumber))
	if isErrNotNil(w, 508, err) {
		return
	}
	errSqlRow := sqlRow.Scan(&userId)
	status, message := service.CheckScanRowSQL(errSqlRow)
	if isStatusNotOK(w, status, message) {
		return
	}
	phoneNumber := userTokenJson.PhoneNumber
	resultHashed := hashedMobileNumber(phoneNumber)
	statusInsertToken, messageInsertToken := insertTokenToUsersTable(resultHashed, phoneNumber)
	w.WriteHeader(statusInsertToken)
	if isStatusNotOK(w, statusInsertToken, messageInsertToken) {
		return
	}
	userToken := requests.UserToken{phoneNumber, resultHashed}
	routes.ServeJson(w, service.GetGeneralMsgType(statusInsertToken, messageInsertToken, userToken))
}
Exemplo n.º 5
0
func decodeActionFriendphoneNumber(body io.ReadCloser) string {
	actionToFriend := requests.ActionToFriend{}
	service.DecodeJson(&actionToFriend, body)
	return actionToFriend.PhoneNumber
}