siamauth

package module
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 15, 2023 License: MIT Imports: 5 Imported by: 0

README

SIAM UB Auth

https://siam.ub.ac.id authentication with scraping method

import:

import (
	"github.com/dnabil/siamauth"
)

run go get command:

go get github.com/dnabil/siamauth

Usage

siamauth constructor

user := siamauth.NewUser()

Currently there's 2 methods which is Login(uname string, pass string) and GetData() -to use GetData(), must be logged in first otherwise will return an error.

ex:

func main(){
	user := siamauth.NewUser()
	err := user.Login("NIM", "PASSWORD")
	if err != nil {
		panic(err)
	}
	err = user.GetData()
	if err != nil {
		panic(err)
	}

	fmt.Println(user.Account.Nama)
	fmt.Println(user.Account.NIM)

	user.Logout()
}

the GetData() method will fill the User struct which looks like this:

type User struct{
	c *colly.Collector

  	Account struct{
		NIM string
		Nama string
		Jenjang string
		Fakultas string
		Jurusan string
		ProgramStudi string
		Seleksi string
		NomorUjian string
	}

	LoginStatus bool
}

You can also check if the user logged in or not with LoginStatus.

That's pretty much it

*I am planning on adding more features like getting schedules, study plan (aka KRS), etc.. but still lazy. Pull requests are welcome :)

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrorNotLoggedIn error = errors.New("please login first")
	ErrorLoggedIn    error = errors.New("already logged in")
)

Functions

This section is empty.

Types

type User

type User struct {
	Account struct {
		NIM          string
		Nama         string
		Jenjang      string
		Fakultas     string
		Jurusan      string
		ProgramStudi string
		Seleksi      string
		NomorUjian   string
		FotoProfil   string
	}
	LoginStatus bool
	// contains filtered or unexported fields
}

func NewUser

func NewUser() User

constructor

func (*User) GetData

func (s *User) GetData() error

func (*User) Login

func (s *User) Login(us string, ps string) error

func (*User) Logout

func (s *User) Logout() error

make sure to defer this method after login, so the phpsessionid won't be misused

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL