예제 #1
0
func (server *Server) tryInscription(u *user.User, message string) {

	socket := *u.Socket

	request := user.GetRegisterRequest(message)
	inscriptionOk, loginOk, passwordOk := user.InscriptionSite(request.Login, request.Password, request.VerifPassword, request.Mail)

	reply := user.RegisterReply{inscriptionOk, loginOk, passwordOk, request.Login, u.GravatarLink, server.roomList.GetRoomsTab()}
	socket.Emit("register", reply.String())

	if inscriptionOk {
		u.Login = request.Login
		u.Mail = request.Mail
		u.CreateGravatarLink()

		server.changeUserRoom(u, constants.DefaultRoom)
	}
}
예제 #2
0
//AddUserInRoom ajoute l'utilisateur dans la salle
func (roomList *RoomList) AddUserInRoom(user *user.User, roomName string) error {
	var err error
	if roomList.GetUsersRoom(user.Login) != nil {
		err = errors.New("AddUserInRoom - l'utilisateur est déjà dans une autre salle")
	} else {
		roomList.rooms[roomName].AddUser(user)
		user.Room = roomName
	}

	return err
}
예제 #3
0
//RemoveUserFromRoom supprime l'utilisateur de la salle
func (roomList *RoomList) RemoveUserFromRoom(user *user.User) bool {
	roomName := user.Room

	room, _ := roomList.rooms[roomName]
	if room != nil {
		room.RemoveUser(user.Login)
	}

	user.Room = ""

	return (room != nil)
}
예제 #4
0
// tryLoginUser try to login user
func (server *Server) tryLoginUser(u *user.User, message string) {

	socket := *u.Socket

	request := user.GetLoginRequest(message)
	login, password, newUser := user.ConnectSite(request.Login, request.Password)

	success := login && password

	reply := user.LoginReply{success, login, password, request.Login, server.roomList.GetRoomsTab(), u.GravatarLink}
	socket.Emit("login", reply.String())

	if success {
		u.Login = newUser.Login
		u.Mail = newUser.Mail
		u.CreateGravatarLink()

		server.changeUserRoom(u, constants.DefaultRoom)
		logger.Print("Connexion d'un utilisateur")
	}
}