Пример #1
0
        public InfoUserModel GetUserInfo(String PhoneNumber)
        {
            var model = new InfoUserModel();
            var _conn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoWebAppDbStr"].ConnectionString);

            if (_conn.State == ConnectionState.Closed)
            {
                _conn.Open();
            }
            string query = string.Format(@"SELECT
	                        U.*,
	                        WM.IsConfirmed,
	                        ro.RoleName FROM Users U
                        Left JOIN webpages_Membership WM on U.Id = WM.UserId
                        Left JOIN webpages_UsersInRoles WU on U.Id = WU.UserId
                        Left JOIN webpages_Roles ro on WU.RoleId = ro.RoleId
                        Where U.UserName = '******'", PhoneNumber);
            //Create command store procedure
            var command = new SqlCommand(query, _conn);

            command.Connection = _conn;
            try
            {
                var reader = command.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        model.Id       = reader.GetInt32(0);
                        model.UserName = reader.IsDBNull(1) ? string.Empty : reader.GetString(1);
                        model.FullName = reader.IsDBNull(2) ? string.Empty : reader.GetString(2);
                        model.Email    = reader.IsDBNull(3) ? string.Empty : reader.GetString(3);
                        model.Address  = reader.IsDBNull(4) ? string.Empty : reader.GetString(4);
                    }
                    reader.Close();
                }
            }
            finally
            {
                command.Connection.Close();
                command.Connection.Dispose();
            }
            return(model);
        }
Пример #2
0
        public InfoUserModel GetUserInfo(String PhoneNumber)
        {
            var model = new InfoUserModel();
            var _conn = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoWebAppDbStr"].ConnectionString);

            if (_conn.State == ConnectionState.Closed)
            {
                _conn.Open();
            }
            //Create command store procedure
            var command = new SqlCommand("UserInfo");

            command.Connection  = _conn;
            command.CommandType = CommandType.StoredProcedure;
            try
            {
                var IdParam = new SqlParameter("@PhoneNumber", PhoneNumber);
                IdParam.Direction = ParameterDirection.Input;
                command.Parameters.Add(IdParam);
                SqlDataReader reader = command.ExecuteReader();
                if (reader.HasRows)
                {
                    while (reader.Read())
                    {
                        model.Id          = reader.GetInt32(0);
                        model.FullName    = reader.GetString(2);
                        model.PhoneNumber = reader.GetString(3);
                        model.Email       = reader.GetString(4);
                        model.Address     = reader.GetString(5);
                        model.Permission  = reader.GetString(6);
                        model.Status      = reader.GetString(7);
                        break;
                    }
                    reader.Close();
                }
            }
            finally
            {
                command.Connection.Close();
                command.Connection.Dispose();
            }
            return(model);
        }
Пример #3
0
        public IActionResult SeeProfile(string id)
        {
            if (id != null)
            {
                int Id = Int32.Parse(id);
                HttpContext.Session.SetInt32("id", Id);
            }

            if (HttpContext.Session.GetInt32("id") == null)
            {
                return(RedirectToAction("Index"));
            }

            string        email = table_conections.UserVideosTable.SingleOrDefault(x => x.Id == HttpContext.Session.GetInt32("id")).Email;
            InfoUserModel info  = table_conections.InfoUser.SingleOrDefault(x => x.Email == email);

            ViewBag.listofRecords = table_conections.UserVideosTable.Where(x => x.Email == email).ToList();
            return(View("SearchInput", info));
        }
Пример #4
0
        public IActionResult SearchInput(string searched)
        {
            if (searched != null)
            {
                HttpContext.Session.SetString("username", searched);
            }
            if (table_conections.UserTable.Where(x => x.Username == HttpContext.Session.GetString("username")).Count() > 0)
            {
                string email = table_conections.UserTable.SingleOrDefault(x => x.Username == HttpContext.Session.GetString("username")).Email;

                InfoUserModel info = table_conections.InfoUser.SingleOrDefault(x => x.Email == email);
                ViewBag.listofRecords = table_conections.UserVideosTable.Where(x => x.Email == email).ToList();
                return(View(info));
            }
            else
            {
                TempData["msg"] = "<script>alert('There is no users with that username.');</script>";
                return(RedirectToAction("Index"));
            }
        }
Пример #5
0
        public async Task <IActionResult> Register(RegisterViewModel model)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = null;
                if (model.Photo != null)
                {
                    string UpLoadFolder = Path.Combine(_hostingEnvironment.WebRootPath, "img/UserIMG");
                    uniqueFileName = Guid.NewGuid().ToString() + "_" + model.Photo.FileName;
                    string FilePath = Path.Combine(UpLoadFolder, uniqueFileName);
                    model.Photo.CopyTo(new FileStream(FilePath, FileMode.Create));
                }
                //1 for Male 0 for Female
                bool uGender = false;
                if (model.Gender == 1)
                {
                    uGender = true;
                }
                var user = new InfoUserModel {
                    UserName = model.UserName, FirstName = model.FirstName, LastName = model.LastName, Email = model.Email, PhoneNumber = model.PhoneNumber, Address = model.Address, Gender = uGender, IMG_url = uniqueFileName
                };
                var result = await userManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await signInManager.SignInAsync(user, isPersistent : false);

                    return(RedirectToAction("index", "home"));
                }
                foreach (var error in result.Errors)
                {
                    ModelState.AddModelError("", error.Description);
                }
            }
            return(View("../Auth/RegisterView", model));
        }
        public ActionResult Manage(InfoUserModel info)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    TaiKhoan tk = new TaiKhoan();
                    tk.HoTen = info.HoTen;
                    tk.Email = info.Email;
                    tk.DiaChi = info.DiaChi;
                    tk.DienThoai = info.DienThoai;
                    tk.GioiTinh = info.GioiTinh;
                    tk.NgaySinh = info.NgaySinh;
                    tk.TenDangNhap = User.Identity.Name;

                    if (service.UpdateAccount(tk))
                    {
                        return RedirectToAction("Manage", new { message = ManageMessageId.ChangeInfoSuccess });
                    }
                    ModelState.AddModelError("", "Có lỗi xảy ra vui lòng thử lại!");
                }
                catch (Exception e)
                {
                    ModelState.AddModelError("", e.Message);
                }
            }
            return View(info);
        }
        public ActionResult Manage(ManageMessageId? message)
        {
            ViewBag.StatusMessage =
                message == ManageMessageId.ChangeInfoSuccess ? "Cập nhật thành công" : "";
            TaiKhoan tk = service.GetAccount(User.Identity.Name);
            InfoUserModel info = new InfoUserModel();
            info.HoTen = tk.HoTen;
            info.Email = tk.Email;
            info.DiaChi = tk.DiaChi;
            info.DienThoai = tk.DienThoai;
            info.GioiTinh = tk.GioiTinh;
            info.NgaySinh = tk.NgaySinh.Value;

            return View(info);
        }
Пример #8
0
        public ObjetRetour Login(LoginModel login)
        {
            if (login == null)
            {
                return(new ObjetRetour());
            }

            var retour = new ObjetRetour();

            try
            {
                string pass = "";
                pass = clsSecurityHash.getSHA256(login.Password);

                var user = _service.Tbuser.FindByCondition(u => u.LoginUser == login.Login && u.Password == pass).FirstOrDefault();

                if (user == null)
                {
                    retour.Etat    = false;
                    retour.Message = "Login ou mot de passe non valide!";
                    retour.Contenu = new LoginModel();
                    return(retour);
                }

                if (user.Password == pass)
                {
                    var secretKey         = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(Startup.SecretKey));
                    var signinCredentials = new SigningCredentials(secretKey, SecurityAlgorithms.HmacSha256);

                    var tokeOptions = new JwtSecurityToken(
                        issuer: Startup.Issuer,// TODO adresse de deploiement du service
                        audience: _strIP,
                        claims: new List <Claim>(),
                        expires: DateTime.Now.AddMinutes(10),//TODO Duree du Token
                        signingCredentials: signinCredentials
                        );

                    var tokenString = new JwtSecurityTokenHandler().WriteToken(tokeOptions);

                    var connexion = new Connexion()
                    {
                        AdresseIpSource   = _strIP,
                        Bsucces           = true,
                        DateConnexion     = DateTime.Now,
                        DateLastConnexion = DateTime.Now,
                        Token             = tokenString,
                        UserId            = (int)user.IdUser
                    };


                    _service.Connexion.Create(connexion);

                    var profil = _service.Tbprofil.FindByCondition(p => p.ProfilId == user.ProfilId).FirstOrDefault();


                    var habilitations = _service.Tbhabilitation.FindByCondition(h => h.ProfilId == profil.ProfilId);
                    var lstIdMenus    = habilitations.Select(m => m.MenuId).ToList();

                    var menuUsers  = _service.Tbmenu.FindByCondition(mp => lstIdMenus.Contains(mp.MenuId));
                    var info       = new InfoUserModel();
                    var loginModel = new LoginModel();

                    loginModel.UserId   = (int)user.IdUser;
                    loginModel.UserName = user.NomPrenUser;
                    loginModel.Login    = user.LoginUser;
                    loginModel.Token    = tokenString;
                    info.Login          = loginModel;

                    info.Menus = new List <MenuModel>();

                    var vueMenuParent = menuUsers.Where(m => m.IdParent == null).OrderBy(o => o.OrdreMenu).ToList();

                    foreach (var menuUser in vueMenuParent)
                    {
                        var menup = new MenuModel();
                        menup.MenuParent = ModelFromDto(menuUser);

                        menup.Menu = LstModelFromDto(menuUsers.Where(me => me.IdParent == menuUser.MenuId).OrderBy(o => o.OrdreMenu).ToList());

                        info.Menus.Add(menup);
                    }

                    // info = getinfoUser(user);
                    _service.Save();

                    retour.Contenu = info;
                    retour.Message = $"SUCCESS";
                    retour.Etat    = true;
                    _logger.LogInfo($"SUCCESS");
                }
            }
            catch (Exception ex)
            {
                retour.Etat    = false;
                retour.Message = ex.Message;
                _logger.LogError(ex.Message);
            }

            return(retour);
        }