Beispiel #1
0
        public ActionResult AddCustomerNote(string customerId, string text)
        {
            int cId = 0;

            Int32.TryParse(customerId, out cId);
            UserDT user = GetLoggedUser();
            NoteDT note = CustomersManager.AddCustomerNote(cId, user.Id, text);

            ViewBag.Note = note;
            return(View("NoteRow"));
        }
Beispiel #2
0
        public UserDT GetDT()
        {
            UserDT res = new UserDT();

            res.Id        = Id;
            res.Email     = Email;
            res.FirstName = FirstName;
            res.LastName  = LastName;
            res.Role      = Role;
            res.RoleId    = RoleId;
            res.AspNetId  = AspNetId;
            return(res);
        }
Beispiel #3
0
        public void DeleteUser(string userId)
        {
            int id = 0;

            Int32.TryParse(userId, out id);
            UserDT user = UsersManager.GetUser(id);

            ApplicationUser toDelte = UserManager.FindById(user.AspNetId);
            bool            result  = System.Web.Security.Membership.DeleteUser(toDelte.UserName);

            if (result)
            {
                UsersManager.DeleteUser(id);
            }
        }
Beispiel #4
0
        public UserDT Register([FromBody] UserDT user)
        {
            IUserManager userManager = ObjectContainer.GetUserManager();

            User u = new User
            {
                Email         = user.Username,
                FullName      = user.FullName,
                SuperiorEmail = user.SuperiorEmail
            };

            userManager.GeneratePassword(u, user.Password);

            userManager.Add(u);

            return(Authenticate(user));
        }
Beispiel #5
0
        public UserDT Authenticate([FromBody] UserDT user)
        {
            IUserManager userManager = ObjectContainer.GetUserManager();

            User u = userManager.Authenticate(user.Username, user.Password);

            if (u == null)
            {
                return(null);
            }

            var tokenHandler    = new JwtSecurityTokenHandler();
            var key             = new SymmetricSecurityKey(Encoding.ASCII.GetBytes("iwjrgoirwhoinwriognmcgweiuohgowimeugmvetwiuhvgkjtejklgjwklfkwipockpoeqkgpovet")); //string is a sectret that should be replaced
            var tokenDescriptor = new SecurityTokenDescriptor
            {
                Subject = new ClaimsIdentity(new Claim[]
                {
                    new Claim(ClaimTypes.Name, u.ID.ToString())
                }),
                Expires            = DateTime.UtcNow.AddDays(user.LongSign ? 365 : 1), //vary this based on the "stay signed in" toggle
                SigningCredentials = new SigningCredentials(key, SecurityAlgorithms.HmacSha256Signature),
                Issuer             = "tieto-trippi-app",
                Audience           = "everyone"
            };
            var token       = tokenHandler.CreateToken(tokenDescriptor);
            var tokenString = tokenHandler.WriteToken(token);

            if (u != null)
            {
                return(new UserDT {
                    Username = u.Email,
                    Token = tokenString
                });
            }

            else
            {
                return(null);
            }

            //authenticate using service

            //create token with userId

            //send user data
        }
Beispiel #6
0
        public static UserDT CreateUser(UserDT user)
        {
            using (CastleClubEntities entities = new CastleClubEntities())
            {
                User newUser = new User();
                newUser.Email     = user.Email;
                newUser.FirstName = user.FirstName;
                newUser.LastName  = user.LastName;
                newUser.Role      = user.Role;
                newUser.AspNetId  = user.AspNetId;
                newUser.Active    = true;

                entities.Users.Add(newUser);
                entities.SaveChanges();

                return(newUser.GetDT());
            }
        }
Beispiel #7
0
        public ActionResult GetReferrersInfo()
        {
            UserDT user = UsersManager.GetUserByAspNetId(User.Identity.GetUserId());

            List <ReferrerInfoDT> sitesInfo = SitesManager.GetReferrersInfo();

            ViewBag.SitesInfo = sitesInfo;

            List <CustomerVM> model = new List <CustomerVM>();
            var todayDate           = DateTime.Now.Date;

            foreach (var customer in ReferrersManagers.GetCustomers(0, true).Where(x => x.CreatedAt >= todayDate))
            {
                string type = string.Empty;
                CustomersManager.GetLastFourDigitCreditCards(customer.Id, out type);

                model.Add(CustomerVM.TransformFromCustomerDT(customer, type));
            }

            return(View(model));
        }
Beispiel #8
0
        public async Task <ActionResult> ManageUsers(NewUserVM model)
        {
            List <UserDT> users = UsersManager.GetUsers();

            if (!ModelState.IsValid)
            {
                ViewBag.Users = users;
                ViewBag.Valid = false;
                return(View(model));
            }

            ApplicationUser user = new ApplicationUser {
                UserName = model.Email, Email = model.Email
            };
            var result = await UserManager.CreateAsync(user, model.Password);

            if (result.Succeeded)
            {
                if (!System.Web.Security.Roles.RoleExists(UserRoleHelper.GetString(model.UserLevel)))
                {
                    System.Web.Security.Roles.CreateRole(UserRoleHelper.GetString(model.UserLevel));
                }
                System.Web.Security.Roles.AddUserToRole(user.UserName, UserRoleHelper.GetString(model.UserLevel));

                UserDT newUser = new UserDT();
                newUser.FirstName = model.FirstName;
                newUser.LastName  = model.LastName;
                newUser.Email     = model.Email;
                newUser.Role      = model.UserLevel;
                newUser.AspNetId  = user.Id;

                newUser = UsersManager.CreateUser(newUser);

                users.Add(newUser);
            }

            ViewBag.Users = users;

            return(View(model));
        }