public ActionResult SocialRegister(SocialRegisterViewModel model)
        {
            var result = _accountService.RegisterByThirdParty(model);

            if (result.IsSuccessful)
            {
                var cookie = Helpers.SetCookie(model.AccountName, false);
                Response.Cookies.Add(cookie);
            }
            return(Json(new { response = result.MessageInfo, status = result.IsSuccessful }));
        }
예제 #2
0
        public OperationResult RegisterByThirdParty(SocialRegisterViewModel model)
        {
            var op = new OperationResult();

            if (model.IsIntegrated)
            {
                if (IsLoginValid(model.AccountName, model.Password))
                {
                    var user = GetUser(model.AccountName, Helpers.ToMD5(model.Password));

                    user.IsIntegrated   = true;
                    user.IsThirdParty   = true;
                    user.SocialPlatform = model.SocialPlatform;
                    user.EditTime       = DateTime.UtcNow.AddHours(8);
                    user.AccountName    = model.AccountName;

                    _repository.Update <Account>(user);
                    _context.SaveChanges();

                    op.IsSuccessful = true;
                    op.MessageInfo  = "註冊成功";
                }
                else
                {
                    op.IsSuccessful = false;
                    op.MessageInfo  = "帳密有誤";
                }
            }
            else
            {
                var account = new RegisterViewModel
                {
                    Email             = model.Email,
                    Address           = null,
                    Gender            = 3,
                    EmailVerification = true,
                    Name                   = model.AccountName,
                    ConfirmPassword        = "",
                    Password               = "",
                    SocialPatform          = model.SocialPlatform,
                    Phone                  = null,
                    IsIntegrated           = false,
                    IsThirdParty           = true,
                    IsProvidedByThirdParty = model.IsIsProvidedByThirdParty
                };

                if (model.IsIsProvidedByThirdParty)
                {
                    account.IsProvidedByUser = model.IsIsProvidedByThirdParty;
                }
                else
                {
                    account.IsProvidedByUser = !string.IsNullOrEmpty(model.Email);
                }

                var result = CreateAccount(account);

                if (result.IsSuccessful)
                {
                    op.IsSuccessful = result.IsSuccessful;
                    op.MessageInfo  = "註冊成功";
                }
                else
                {
                    op.IsSuccessful = result.IsSuccessful;
                    op.MessageInfo  = "註冊失敗";
                }
            }

            return(op);
        }