LMSouq
moodle-core Open

How do I apply authentication to my ionic app using moodle?

US
user758078
1 month ago
3 views
Problem Description
I'm currently working on a Ionic app with a login validation feature. The objective is to verify user-entered login details by cross-referencing them with the corresponding username and password stored in the database. However, I'm faced with the challenge of integrating Moodle for authentication. I have a Moodle site established, and a database is already in place, but I'm uncertain about the most effective approach to tackle this integration. Any guidance or insights would be greatly appreciated. Here is the code I currently have for the login validation: ``` import { Component } from '@angular/core'; import { NavController } from '@ionic/angular'; @Component({ selector: 'app-home', templateUrl: 'home.page.html', styleUrls: ['home.page.scss'], }) export class HomePage { username!: string; password!: string; constructor(private navCtrl: NavController) {} login() { if (this.username === '123' && this.password === '123') { // Navigate to another page after successful login this.navCtrl.navigateForward('/home/report-page'); } else { // Show an error message for unsuccessful login console.log('Invalid username or password'); } } } ``` Update on a new attempt: ``` login() { const moodleEndpoint = 'https://mysite/webservice/rest/server.php'; const webServiceToken = 'your_web_service_token'; const params = { wstoken: webServiceToken, wsfunction: 'core_user_login', moodlewsrestformat: 'json', username: this.username, password: this.password, }; this.http.get(moodleEndpoint, { params }).subscribe( (response: any) => { if (response.errorcode) { console.log('Login failed. Error: ' + response.errorcode); } else { // Successful login console.log('Login successful'); // You can navigate to another page or perform other actions here this.navCtrl.navigateForward('/home/report-page'); } }, (error) => { console.error('Login failed. Error: ', error); } ); } } ``` I'm not too sure what mooodle webservice I would use tho.

AI-Generated Solution

Powered by LMSouq AI · GPT-4.1-mini

✓ Solution Ready
Analyzing problem and generating solution…
Was this solution helpful?
Back to Knowledge Base