示例#1
0
        static void CreateUser()
        {
            User user = new User();

            user.Name = Guid.NewGuid().ToString();

            Random r = new Random();

            user.Age = r.Next();

            ProductContext productContext = new ProductContext(new Context());
            List <Product> products       = (List <Product>)productContext.ReadAll();

            int productsCount = r.Next(1, products.Count);

            List <Product> productsForUser = new List <Product>(productsCount);

            for (int i = 0; i < productsCount; i++)
            {
                productsForUser.Add(products[r.Next(0, products.Count)]);
            }

            user.Products = productsForUser;

            UserContext userContext = new UserContext(new Context());

            userContext.Create(user);

            Console.WriteLine("User created successsfully!");
        }
        public async System.Threading.Tasks.Task <ActionResult> Register(RegisterModel model, HttpPostedFileBase uploadedFile)
        {
            if (ModelState.IsValid)
            {
                User user = null;
                //user = db.Users.Find(new FilterDefinitionBuilder<User>().Regex("Email", new BsonRegularExpression(model.Email))).ToList()[0];

                user = await db.GetUserE(model.Email);

                if (user == null)
                {
                    String psswrd = await db.Encrypt(model.Email, model.Password);

                    Session["hasImage"] = false;
                    Session["IsAdmin"]  = false;
                    Session["Name"]     = model.Name;
                    await db.Create(new User { Email = model.Email, Password = psswrd, Name = model.Name, Number = model.Number, DateOfBirth = model.DateOfBirth });

                    if (uploadedFile != null)
                    {
                        Session["hasImage"] = true;
                        await db.StoreImage(model.Email, uploadedFile.InputStream, uploadedFile.FileName);
                    }
                    FormsAuthentication.SetAuthCookie(model.Email, true);
                    return(RedirectToAction("Index", "Home"));
                }
                else
                {
                    ModelState.AddModelError("", "User with this login is existing");
                }
            }
            return(View(model));
        }
 public ActionResult Register(User user)
 {
     if (UserContext.Check(user) > 0)
     {
         return(View());
     }
     if (UserContext.Create(user) < 1)
     {
         return(View());
     }
     Session.Add(Common.USER_SESSION, user);
     return(RedirectToAction("Index", "InfoUser"));
 }
示例#4
0
        public static AuthenticationResponse CreateUser(User user)
        {
            var authResponse = new AuthenticationResponse(ResponseType.Create)
            {
                Code = ResponseCode.Error, User = null
            };

            bool isUserCreated = userContext.Create(user);

            if (isUserCreated)
            {
                authResponse.Code = ResponseCode.Created;
                authResponse.User = user;
            }

            return(authResponse);
        }
示例#5
0
        public int register(Usuario user)
        {
            Usuario u = new Usuario();

            u.IdiomasApr    = user.IdiomasApr;
            u.MedioPrac     = user.MedioPrac;
            u.Nombre        = user.Nombre;
            u.POrigen       = user.POrigen;
            u.Sexo          = user.Sexo;
            u.Hobbies       = user.Hobbies;
            u.Edad          = user.Edad;
            u.Contrasena    = user.Contrasena;
            u.NombreUsuario = user.NombreUsuario;
            u.TipoU         = 2;
            u.IdiomasEns    = user.IdiomasEns;

            _context.Create(u);
            return(1);
        }
示例#6
0
        public async Task <ActionResult <UserPostResponse> > PostUser(PostUser user, [FromQuery(Name = "isSignIn")] bool isSignIn = false)
        {
            if (isSignIn)
            {
                var authUser = await _context.IsAuth(user.login, user.password, user.teamName);

                if (authUser != null)
                {
                    return(new UserPostResponse(authUser));
                }

                return(ValidationProblem("Team name, login or password is incorrect."));
            }

            bool isUnique = await _context.IsUnique(user.login, null, user.teamId, user.teamName);

            bool isTeamAuth = await _context.IsTeamAuth(user.teamName, user.teamPassword);

            if (!isUnique)
            {
                return(ValidationProblem("Login must be unique."));
            }

            if (!isTeamAuth)
            {
                return(ValidationProblem("Team name or team password is incorrect."));
            }

            User correctUser = new User(user.login, user.password, user.teamName);

            await _context.Create(correctUser);

            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetUser), new { id = user.id }, new UserPostResponse(correctUser)));
        }
示例#7
0
        public HttpResponseMessage Register(CUserInfo userInfo)
        {
            HttpResponseMessage response;

            if (userInfo == null)
            {
                response = Request.CreateResponse(HttpStatusCode.BadRequest, "User has no data to register!");
                return(response);
            }

            try
            {
                // check if such user already exists in context
                CUser checkCUser = _userContext.GetByName(userInfo.Name);

                if (checkCUser.Name != null)
                {
                    response = Request.CreateResponse(HttpStatusCode.BadRequest, "Such user already exists!");
                    return(response);
                }


                // check if such email is already taken by someone else
                CUser checkEmail = _userContext.GetByName(userInfo.Email);
                if (checkEmail.Email != null)
                {
                    response = Request.CreateResponse(HttpStatusCode.BadRequest, "Such email is already taken!");
                    return(response);
                }

                // in CUser CTOR new Guid and passwordHash is generated from given password
                CUser newUser = new CUser(Guid.NewGuid(), userInfo.Name, userInfo.Password, userInfo.Email);

                // Insert new user in DB
                Int32 rowsInserted = _userContext.Create(newUser);

                // Create 'default' playlist for user files
                CPlaylist defaultPlaylist = new CPlaylist(Guid.NewGuid(), "default", newUser.Guid, false);
                _playlistContext.Create(defaultPlaylist);

                // Create new folder for user files
                DirectoryInfo directoryInfo = new DirectoryInfo(System.Web.Hosting.HostingEnvironment.MapPath($@"~/App_Data"));
                if (!Directory.Exists(directoryInfo.ToString() + "\\UserFiles"))
                {
                    Directory.CreateDirectory(directoryInfo.ToString() + "\\UserFiles");
                }
                // create directory for user files
                string fullPath = System.Web.Hosting.HostingEnvironment.MapPath($@"~/App_Data/UserFiles/{newUser.Name}");
                Directory.CreateDirectory(fullPath);

                // create directory for thumbnails of the videos
                string thumbnailsPath = System.Web.Hosting.HostingEnvironment.MapPath($@"~/App_Data/UserFiles/{newUser.Name}/Thumbnails");
                Directory.CreateDirectory(thumbnailsPath);

                userInfo = newUser.ToCUserInfo();
                response = Request.CreateResponse(HttpStatusCode.OK, userInfo);

                return(response);
            }
            catch (Exception e)
            {
                //todo: log
                HttpContext.Current.Response.StatusCode = (Int32)HttpStatusCode.BadRequest;
                throw new ContextException(e.Message, e);
            }
        }
示例#8
0
 public Users Create(Users user)
 {
     using UserContext context = new UserContext();
     return(context.Create(user));
 }