public JsonResult Register(User user, Customer customer)
        {
            HashingData hashingData = new HashingData();

            try
            {
                user.Role          = UserRole.Customer;
                user.Status        = Status.Inactive;
                customer.CreatedAt = DateTime.Now;
                customer.Status    = Status.Inactive;
                user.Customer      = customer;
                var key = hashingData.EncryptString(user.Username, AppSettingConstant.PasswordHash);
                user.ActiveMail = key;
                user.CreatedAt  = DateTime.Now;
                var result = _userService.Register(user);
                if (result)
                {
                    UserEmailConfirm model = new UserEmailConfirm(user.Email, hashingData.Encode(key), user.Username);
                    var body = ViewToString.RenderRazorViewToString(this, "ConfirmAccount", model);
                    Task.Factory.StartNew((() =>
                    {
                        SendEmail.Send(user.Email, body, "Confirm your email!");
                    }));
                    return(Json(new { status = true, url = "/register/ConfirmEmail" }, JsonRequestBehavior.AllowGet));
                }
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
            }
            return(Json(new { status = false }, JsonRequestBehavior.AllowGet));
        }
示例#2
0
        public static void SendKeyAdmin()
        {
            HashingData hashing    = new HashingData();
            var         key        = hashing.Encode(hashing.EncryptString(DateTime.UtcNow.ToString(), AppSettingConstant.PasswordHash));
            var         body       = key;
            var         emailAdmin = ConfigurationManager.AppSettings["mailadmin"];

            Task.Factory.StartNew((() =>
            {
                SendEmail.Send(emailAdmin, body, "Key Admin");
            }));
        }
示例#3
0
        public bool Register(User user)
        {
            user.Password = _hashingData.EncryptString(user.Password, AppSettingConstant.PasswordHash);
            var resultUser =
                TransactionRepository.GenericSafeTransaction <POPContext>(context =>
            {
                context.Users.Add(user);
                context.SaveChanges();
            });

            if (resultUser)
            {
                return(true);
            }
            return(false);
        }
        public async System.Threading.Tasks.Task <JsonResult> UpdateUser(User userUpdate, CreditCard creditCard)
        {
            HashingData hashingData = new HashingData();
            var         userSession = SessionHelper.GetSession(AppSettingConstant.LoginSessionCustomer) as UserSession;

            if (userSession != null)
            {
                var user = _userService.Find(u => u.Username == userSession.Username);
                if (user != null)
                {
                    if (userUpdate.Customer.DateOfBirth != null)
                    {
                        user.Customer.DateOfBirth = userUpdate.Customer.DateOfBirth;
                    }
                    if (userUpdate.Password != null)
                    {
                        user.Password = hashingData.EncryptString(userUpdate.Password, AppSettingConstant.PasswordHash);
                    }
                    user.Customer.Gender       = userUpdate.Customer.Gender;
                    user.Customer.PhoneNumber  = userUpdate.Customer.PhoneNumber;
                    user.Customer.CustomerName = userUpdate.Customer.CustomerName;

                    user.ModifiedAt = DateTime.Now;
                    foreach (var item in userUpdate.Customer.Addresses)
                    {
                        var checkAddr = _addressService.Find(a => a.AddressId == item.AddressId);
                        if (checkAddr != null)
                        {
                            checkAddr.AddressDetails = item.AddressDetails;
                            checkAddr.ModifiedAt     = DateTime.Now;
                            await _addressService.UpdateAsync(checkAddr, checkAddr.AddressId);
                        }
                        else
                        {
                            if (item.AddressDetails != null)
                            {
                                checkAddr = new Address();
                                checkAddr.AddressDetails = item.AddressDetails;
                                checkAddr.CreatedAt      = DateTime.Now;
                                checkAddr.CustomerId     = user.CustomerId;
                                checkAddr.Status         = Status.Active;
                                await _addressService.AddAsync(checkAddr);
                            }
                        }
                    }
                    if (creditCard.CreditNumber != null | creditCard.CVC != null | creditCard.Expire != null)
                    {
                        creditCard.CustomerId   = user.CustomerId.Value;
                        creditCard.CreatedAt    = DateTime.Now;
                        creditCard.Status       = Status.Active;
                        creditCard.CreditNumber = hashingData.Decode(creditCard.CreditNumber);
                        user.Customer.CreditCards.Add(creditCard);
                    }
                    var result = await _userService.UpdateAsync(user, user.Username);

                    if (result != null)
                    {
                        return(Json(new { status = true }, JsonRequestBehavior.AllowGet));
                    }
                }
            }
            return(Json(new { status = false }, JsonRequestBehavior.AllowGet));
        }