Esempio n. 1
0
        public async Task <IActionResult> Create(RequestMembers member)
        {
            Regex regex = new Regex(@"^(?=.*\d)(?=.*[a-z])(?=.*[A-Z]).{10,30}$");

            if (!regex.IsMatch(member.Password))
            {
                return(StatusCode(Status400BadRequest, new ResponseMessage {
                    Message = "字串長度在 10 ~ 30 個字母之間,且至少一個小寫英文字母、大寫英文字母和數字。"
                }));
            }

            if (member.Password != member.CheckPassword)
            {
                return(StatusCode(Status400BadRequest, new ResponseMessage {
                    Message = "密碼與確認密碼不符合"
                }));
            }
            member.Password = StringEncryptExtension.aesEncryptBase64(member.Password, member.Email);

            try
            {
                var mem = new Members()
                {
                    Email    = member.Email,
                    IsVerify = member.IsVerify,
                    Name     = member.Name,
                    Password = member.Password
                };
                _context.Add(mem);
                await _context.SaveChangesAsync();

                return(Ok());
            }
            catch (Exception ex)
            {
                return(StatusCode(Status400BadRequest, new ResponseMessage {
                    Message = "註冊失敗"
                }));
            }
        }