Example #1
0
        public async Task <KeyValuePair <bool, string> > CheckUserName(MainApiDbContext context)
        {
            //Reprocess the UserName string to remove all characters as \s \t \r \n
            UserName = string.Concat(UserName.Where(c => !char.IsWhiteSpace(c)));

            //Check if UserName is already used
            if (await context.Users.AnyAsync(u => u.Username == UserName))
            {
                return(new KeyValuePair <bool, string>(false, "UsernameClashed"));
            }

            //Check if UserName matches the required format
            var regex = new Regex(@"^[\w\d_]{4,12}$");

            return(!regex.Match(UserName).Success
                ? new KeyValuePair <bool, string>(false, "RegexMismatched")
                : new KeyValuePair <bool, string>(true, string.Empty));
        }
Example #2
0
        public async Task <KeyValuePair <bool, string> > CheckEmail(MainApiDbContext context)
        {
            //Remove all starting and trailing spaces
            Email = Email.Trim(' ').ToLower();

            //Since dots has no matter in email, simplify it by removing all dots
            var simplified = Email.Replace(".", string.Empty);

            //Check if Email is already used
            if (await context.Users.AnyAsync(u => u.Email.Replace(".", string.Empty) == simplified))
            {
                return(new KeyValuePair <bool, string>(false, "EmailClashed"));
            }

            //Check for Email format
            var regex = new Regex(@"^([\w\.\-]+)@([\w\-]+)((\.(\w){2,3})+)$");

            return(!regex.Match(Email).Success
                ? new KeyValuePair <bool, string>(false, "InvalidEmail")
                : new KeyValuePair <bool, string>(true, string.Empty));
        }
 public AccountController(MainApiDbContext context)
 {
     _context      = context;
     _emailService = new EmailService();
 }