aboutsummaryrefslogtreecommitdiff
path: root/Timeline/Services/UserService.cs
blob: ab5a31bb0c12f7ccd19c4a299a9f435ab1efb2ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Timeline.Entities;

namespace Timeline.Services
{
    public interface IUserService
    {
        /// <summary>
        /// Try to anthenticate with the given username and password.
        /// </summary>
        /// <param name="username">The username of the user to be anthenticated.</param>
        /// <param name="password">The password of the user to be anthenticated.</param>
        /// <returns><c>null</c> if anthentication failed.
        /// An instance of <see cref="User"/> if anthentication succeeded.</returns>
        User Authenticate(string username, string password);
    }

    public class UserService : IUserService
    {
        private readonly IList<User> _users = new List<User>{
            new User { Id = 0, Username = "admin", Password = "admin", Roles = new string[] { "User", "Admin" } },
            new User { Id = 1, Username = "user", Password = "user", Roles = new string[] { "User"} }
        };

        public User Authenticate(string username, string password)
        {
            return _users.FirstOrDefault(user => user.Username == username && user.Password == password);
        }
    }
}