Ejemplo n.º 1
0
 /// <summary>
 /// 注册
 /// </summary>
 /// <param name="m"></param>
 /// <returns></returns>
 public (Status status, string jwt) Register(UserInfos m)
 {
     if (AnyNullOrWhiteSpace(m.Uid, m.Name, m.Pwd))
     {
         return(Status.InputIllegal, null);
     }
     if (!Regex.IsMatch(m.Uid, _opt.UidRegex))
     {
         return(Status.UidIllegal, null);
     }
     if (!Regex.IsMatch(m.Pwd, _opt.PwdRegex))
     {
         return(Status.PwdIllegal, null);
     }
     if (_db.Find(m.Uid) != null)
     {
         return(Status.UidHasExist, null);
     }
     _db.Add(new AppUser(m));
     return(Status.Ok, MakeJwt(m.Uid, RoleTypes.Vistor));
 }
Ejemplo n.º 2
0
 public Status AddUser(UserInfos m)
 {
     if (AnyNullOrWhiteSpace(m.Uid, m.Name, m.Role, m.Pwd))
     {
         return(Status.InputIllegal);
     }
     if (!Regex.IsMatch(m.Uid, _opt.UidRegex))
     {
         return(Status.UidIllegal);
     }
     if (!Regex.IsMatch(m.Pwd, _opt.PwdRegex))
     {
         return(Status.PwdIllegal);
     }
     if (_db.Find(m.Uid) != null)
     {
         return(Status.UidHasExist);
     }
     _db.Add(new AppUser(m));
     return(Status.Ok);
 }
Ejemplo n.º 3
0
        public ActionResult Register(string userName, string password, string firstName, string lastName)
        {
            var user = _userDbContext.FindByEmail(userName);

            if (user != null)
            {
                var errorResponse = new ErrorResponseViewModel
                {
                    HasErrors = true,
                    Errors    = new List <string> {
                        "This email address is already registered"
                    }
                };
                return(View(errorResponse));
            }

            var createdUser = _userDbContext.Add(new User
            {
                Email     = userName,
                Password  = CalculateMD5Hash(password),
                IsActive  = false,
                FirstName = firstName,
                LastName  = lastName
            });

            if (createdUser != null)
            {
                var userId           = createdUser.Id.ToString();
                var identifier       = Convert.ToBase64String(Encoding.Unicode.GetBytes(userId));
                var confirmationLink = $"http://adslicenta.azurewebsites.net/Home/ConfirmEmail?id={identifier}";
                var subject          = "Conrfim your email";
                var body             = $"Click <a href='{confirmationLink}' target='_blank'>here</a> to register.";

                _emailService.SendEmail(createdUser.Email, subject, body);
                TempData["isEmailSent"] = true;
            }
            return(RedirectToAction("Index", "Home"));
        }