コード例 #1
0
        public IActionResult Index()
        {
            CredentialManage        credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));
            List <AccountManageDTO> accounts   = GetApiAccountManage.GetAccountManages(credential.JwToken)
                                                 .Select(p => new AccountManageDTO()
            {
                Email           = p.Email,
                AccountRoleName = GetApiAccountRoles.GetAccountRoles().SingleOrDefault(k => k.AccountRoleId == p.AccountRoleId).AccountRoleName,
                Password        = p.Password,
                FullName        = p.FullName,
                IsActivated     = p.IsActivated,
                Avatar          = p.Avatar,
                Address         = p.Address
            }).ToList();

            return(View(accounts));
        }
コード例 #2
0
ファイル: AuthController.cs プロジェクト: ttthien111/PET
        public IActionResult Login(LoginModel login)
        {
            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(Common.Constants.BASE_URI);

                var postTask = client.PostAsJsonAsync <LoginModel>("LoginAuthentication/Authenticate", login);
                postTask.Wait();

                var result = postTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    // get credential return
                    var readTask = result.Content.ReadAsAsync <CredentialModel>();
                    readTask.Wait();
                    CredentialModel credential = readTask.Result;

                    // get user profile
                    UserProfile profile = GetApiUserProfile.GetUserProfiles().SingleOrDefault(p => p.AccountId == Convert.ToInt32(credential.AccountId));

                    // get account && role
                    Account account = GetApiAccounts.GetAccounts().SingleOrDefault(p => p.AccountId == profile.AccountId);
                    account.AccountRole = GetApiAccountRoles.GetAccountRoles().SingleOrDefault(p => p.AccountRoleId == account.AccountRoleId);

                    profile.Account = account;

                    credential.Profile = profile;

                    // set 1 session for credential
                    HttpContext.Session.SetObject("vm", credential);

                    if (login.returnUrl != null)
                    {
                        return(Redirect(login.returnUrl));
                    }

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ViewBag.error = "Tài khoản hoặc mật khẩu không đúng";
                }
            }

            return(View());
        }
コード例 #3
0
        public IActionResult UpdateProfile(string email)
        {
            CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE));
            AccountManage    profile    = GetApiAccountManage.GetAccountManages(credential.JwToken)
                                          .Select(p => new AccountManage()
            {
                Email         = p.Email,
                AccountRoleId = p.AccountRoleId,
                FullName      = p.FullName,
                IsActivated   = p.IsActivated,
                Avatar        = p.Avatar,
                Address       = p.Address
            }).SingleOrDefault(p => p.Email == email);

            ViewBag.AccountRoleName = GetApiAccountRoles.GetAccountRoles().SingleOrDefault(k => k.AccountRoleId == profile.AccountRoleId).AccountRoleName;
            ViewBag.Email           = profile.Email;
            ViewBag.FullName        = profile.FullName;
            ViewBag.DiaChi          = profile.Address;
            return(View());
        }
コード例 #4
0
        public IActionResult Create(AccountManageDTO dto, IFormFile Avatar)
        {
            var obj = dto;

            if (dto.Password == null)
            {
                return(NoContent());
            }

            AccountManage accountManage = new AccountManage()
            {
                FullName      = dto.FullName,
                Address       = dto.Address,
                Email         = dto.Email,
                IsActivated   = dto.IsActivated,
                Password      = Encryptor.MD5Hash(dto.Password),
                AccountRoleId = GetApiAccountRoles.GetAccountRoles().SingleOrDefault(q => q.AccountRoleName == dto.AccountRoleName).AccountRoleId
            };

            string accountImg = Encryptor.RandomString(12);
            string extension  = Avatar != null?Path.GetExtension(Avatar.FileName) : "";

            if (Avatar != null)
            {
                if (SlugHelper.CheckExtension(extension))
                {
                    var path = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", "images/avatar", accountImg + extension);
                    using (var file = new FileStream(path, FileMode.Create))
                    {
                        Avatar.CopyTo(file);
                    }
                    accountManage.Avatar = accountImg + extension;
                }
                else
                {
                    ModelState.AddModelError("", Constants.EXTENSION_IMG_NOT_SUPPORT);
                    return(Content(Constants.EXTENSION_IMG_NOT_SUPPORT));
                }
            }
            else
            {
                accountManage.Avatar = "denyPaw.png";
            }


            //account avatar
            CredentialManage credential = JsonConvert.DeserializeObject <CredentialManage>(HttpContext.Session.GetString(Constants.VM_MANAGE) != null ? HttpContext.Session.GetString(Constants.VM_MANAGE) : "");
            string           token      = credential.JwToken;

            using (HttpClient client = HelperClient.GetClient(token))
            {
                client.BaseAddress = new Uri(Common.Constants.BASE_URI);

                var postTask = client.PostAsJsonAsync <AccountManage>(Constants.ACCOUNT_MANAGE, accountManage);
                postTask.Wait();

                var result = postTask.Result;

                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <Product>();
                    readTask.Wait();
                }
                return(RedirectToAction(nameof(Index)));
            }
        }
コード例 #5
0
 public IActionResult Create()
 {
     ViewBag.AccountRoleName = GetApiAccountRoles.GetAccountRoles().ToList();
     return(View());
 }
コード例 #6
0
ファイル: AuthController.cs プロジェクト: ttthien111/PET
        public IActionResult LoginExternal(string loginEx)
        {
            Account     createdAccount = null;
            UserProfile userProfile    = null;

            LoginEx login = JsonConvert.DeserializeObject <LoginEx>(loginEx);

            if (login.Email == null)
            {
                login.Email = "customer_" + Encryptor.RandomString(6) + "@petshop.com";
            }

            UserProfile profile = GetApiUserProfile.GetUserProfiles().SingleOrDefault(p => p.UserProfileEmail == login.Email);

            // create if null
            if (profile == null)
            {
                string passwordTemp = Encryptor.RandomString(12);
                // create account
                RegisterModel register = new RegisterModel()
                {
                    Email           = login.Email,
                    FirstName       = login.FirstName,
                    MiddleName      = login.MiddleName,
                    LastName        = login.LastName,
                    Password        = passwordTemp,
                    IsLoginExternal = true,
                    DOB             = "1990/1/1",
                    Avatar          = "noimage.png"
                };

                createdAccount = CreateAccount(register);

                // create profile
                userProfile = CreateProfile(createdAccount, register);
                // create user score
                CreateUserScore(userProfile);
            }


            // request token login
            using (HttpClient client = new HttpClient())
            {
                client.BaseAddress = new Uri(Constants.BASE_URI);

                var postTask = client.PostAsJsonAsync <LoginEx>("LoginAuthentication/AuthenticateExternal", login);
                postTask.Wait();

                var result = postTask.Result;
                if (result.IsSuccessStatusCode)
                {
                    var readTask = result.Content.ReadAsAsync <CredentialModel>();
                    readTask.Wait();

                    CredentialModel response = readTask.Result;

                    // get user profile
                    UserProfile res_profile = GetApiUserProfile.GetUserProfiles().SingleOrDefault(p => p.AccountId == Convert.ToInt32(response.AccountId));

                    // get account && role
                    Account account = GetApiAccounts.GetAccounts().SingleOrDefault(p => p.AccountId == profile.AccountId);
                    account.AccountRole = GetApiAccountRoles.GetAccountRoles().SingleOrDefault(p => p.AccountRoleId == account.AccountRoleId);

                    profile.Account = account;

                    response.Profile = profile;

                    // set 1 session for credential
                    HttpContext.Session.SetObject("vm", response);

                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    return(View());
                }
            }
        }