Ejemplo n.º 1
0
        public ActionResult EditProfile()
        {
            var user  = this.db.Users.FirstOrDefault(u => u.UserName.Equals(this.currentUser.UserName));
            var model = new ExtendedIdentityModels {
                UserName = user?.UserName, FullName = user?.FullName, Email = user?.Email, ProfilePhoto = user?.ProfilePhoto, Biography = user?.Biography
            };

            return(this.View(model));
        }
Ejemplo n.º 2
0
        public async Task <ActionResult> Register(ExtendedIdentityModels model)
        {
            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName
                };

                if (model.UserProfilePicture != null)
                {
                    if (model.UserProfilePicture.ContentLength > (4 * 1024 * 1024))
                    {
                        ModelState.AddModelError("CustomError", "Image can not be lager than 4MB.");
                        return(View());
                    }
                    if (!(model.UserProfilePicture.ContentType == "image/jpeg" || model.UserProfilePicture.ContentType == "image/gif"))
                    {
                        ModelState.AddModelError("CustomError", "Image must be in jpeg or gif format.");
                    }

                    byte[] data = new byte[model.UserProfilePicture.ContentLength];
                    model.UserProfilePicture.InputStream.Read(data, 0, model.UserProfilePicture.ContentLength);

                    user.ProfilePicture = data;
                }



                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await this.UserManager.AddToRoleAsync(user.Id, "Regular");

                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);

                    // For more information on how to enable account confirmation and password reset please visit http://go.microsoft.com/fwlink/?LinkID=320771
                    // Send an email with this link
                    // string code = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);
                    // var callbackUrl = Url.Action("ConfirmEmail", "Account", new { userId = user.Id, code = code }, protocol: Request.Url.Scheme);
                    // await UserManager.SendEmailAsync(user.Id, "Confirm your account", "Please confirm your account by clicking <a href=\"" + callbackUrl + "\">here</a>");

                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }

            // If we got this far, something failed, redisplay form
            return(View(model));
        }
Ejemplo n.º 3
0
        public async Task <ActionResult> Register(ExtendedIdentityModels model)
        {
            if (model.ProfilePicture != null)
            {
                if (model.ProfilePicture.ContentLength > (4 * 1024 * 1024))
                {
                    ModelState.AddModelError("customerError", "Image can not be larger than 4MB");
                    return(View());
                }
            }

            byte[] data = new byte[model.ProfilePicture.ContentLength];
            model.ProfilePicture.InputStream.Read(data, 0, model.ProfilePicture.ContentLength);


            if (ModelState.IsValid)
            {
                var user = new ApplicationUser {
                    UserName = model.Email, Email = model.Email, FirstName = model.FirstName, LastName = model.LastName, JobTitle = model.JobTitle, TeamName = model.TeamName, ImageByte = data
                };
                var result = await UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    UserManager.AddToRole(user.Id, "Administrator");
                    await SignInManager.SignInAsync(user, isPersistent : false, rememberBrowser : false);


                    return(RedirectToAction("Index", "Home"));
                }
                AddErrors(result);
            }


            return(View(model));
        }
        public async Task <ActionResult> Register(ExtendedIdentityModels model)
        {
            bYteMeDbContext db = new bYteMeDbContext();

            if (this.ModelState.IsValid)
            {
                if (model.UserProfilePicture != null)
                {
                    if (model.UserProfilePicture.ContentLength > (4 * 1024 * 1024))
                    {
                        this.ModelState.AddModelError("", "Изображението не може да е по-голямо от 4MB.");
                        return(this.View());
                    }
                    if (!(model.UserProfilePicture.ContentType == "image/jpeg" || model.UserProfilePicture.ContentType == "image/gif"))
                    {
                        this.ModelState.AddModelError("", "Изображението трябва да е в jpeg или gif формат.");
                    }
                }

                byte[] data;
                if (model.UserProfilePicture == null)
                {
                    FileStream fs = new FileStream(
                        AppDomain.CurrentDomain.BaseDirectory + "/images/default-profile-picture.jpg",
                        FileMode.Open,
                        FileAccess.Read);
                    BinaryReader br    = new BinaryReader(fs);
                    byte[]       image = br.ReadBytes((int)fs.Length);
                    br.Close();
                    fs.Close();
                    data = image;
                }
                else
                {
                    data = new byte[model.UserProfilePicture.ContentLength];
                    model.UserProfilePicture.InputStream.Read(data, 0, model.UserProfilePicture.ContentLength);
                }
                if (db.Users.Any(u => u.UserName == model.UserName))
                {
                    this.ModelState.AddModelError("", "вече има пич с такова потребителско име");
                }
                if (db.Users.Any(u => u.Email == model.Email))
                {
                    this.ModelState.AddModelError("", "зает е имейла");
                }
                var user = new User()
                {
                    UserName     = model.UserName,
                    FullName     = model.FullName,
                    Biography    = model.Biography,
                    ProfilePhoto = data,
                    Password     = model.Password,
                    Email        = model.Email
                };
                var result = await this.UserManager.CreateAsync(user, model.Password);

                if (result.Succeeded)
                {
                    await this.SignInManager.SignInAsync(user, false, false);

                    return(this.RedirectToAction("Index", "Home"));
                }
                this.AddErrors(result);
            }
            // If we got this far, something failed, redisplay form
            return(this.View(model));
        }