Ejemplo n.º 1
0
        /// <summary>
        /// Check if exist user with this login
        /// </summary>
        /// <param name="email">user's login</param>
        /// <returns>is exist</returns>
        public async Task <bool> IsUserExist(string email)
        {
            Logins existed = await Logins.FirstOrDefaultAsync(e => e.Login == email);

            if (existed == null)
            {
                return(false);
            }

            return(true);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Get register key
        /// </summary>
        /// <param name="email">users email</param>
        /// <returns>key</returns>
        public async Task <string> GetRegisterKey(string email)
        {
            Logins user = await Logins.FirstOrDefaultAsync(l => l.Login == email);

            if (user != null)
            {
                return(user.RegisterKey);
            }

            return(null);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Get email by user role
        /// </summary>
        /// <param name="role">role</param>
        /// <returns>email</returns>
        public async Task <string> GetEmail(Roles role)
        {
            Logins user = await Logins.FirstOrDefaultAsync(l => l.RoleId == role.Id);

            if (user != null)
            {
                return(user.Login);
            }

            return(null);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Find user by login
        /// </summary>
        /// <param name="login">credential's login</param>
        /// <returns>user's id</returns>
        public async Task <int> FindByLogin(string login)
        {
            Logins existed = await Logins.FirstOrDefaultAsync(x => x.Login == login);

            if (existed == null)
            {
                return(0);
            }

            return(existed.Id);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Confirm email if link was clicked
        /// </summary>
        /// <param name="userId"> user id</param>
        /// <param name="token">register key</param>
        /// <returns>true/false</returns>
        public async Task <bool> Confirm(int userId, string token)
        {
            Logins user = await Logins.FirstOrDefaultAsync(l => l.Id == userId);

            if (user != null && user.RegisterKey == token)
            {
                user.Status = "Confirmed";
                await SaveChangesAsync();

                return(true);
            }

            return(false);
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Check is email confirmed
        /// </summary>
        /// <param name="email">users email</param>
        /// <returns>true/false</returns>
        public async Task <bool> IsConfirmed(string email)
        {
            Logins user = await Logins.FirstOrDefaultAsync(l => l.Login == email);

            if (user != null)
            {
                if (user.Status.ToLower() == "confirmed")
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }

            return(false);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Check is usuer already in system
        /// </summary>
        /// <param name="email">users email</param>
        /// <returns>token if authorized</returns>
        public async Task <string> IsAuthorized(string email)
        {
            Logins user = await Logins.FirstOrDefaultAsync(l => l.Login == email);

            if (user != null)
            {
                Sessions current = await Sessions.LastOrDefaultAsync(s => s.UserId == user.Id);

                if (current != null && current.ExpiredDate > DateTime.Now)
                {
                    return(current.Token);
                }

                return(null);
            }
            else
            {
                return(null);
            }
        }