Exemple #1
0
        public async Task <IHttpActionResult> ResendConfirmationEmail(EmailConfirmationRecovery model)
        {
            var user = await UserManager.FindByEmailAsync(model.Email);

            if (user != null)
            {
                var emailToken = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                //mvc
                //var confirmationLink = new Uri(Url.Link("ConfirmEmailRoute", new { userId = user.Id, token = emailToken }));

                var confirmationLinkFrontend = new Uri("http://localhost:4200/email-send").AddQuery("email", model.Email).AddQuery("token", emailToken);
                SendEMailHelper.Send(user.Email, "Confirm your email for transport service", "Please confirm your email by clicking <a href=\"" + confirmationLinkFrontend + "\">here</a>");
            }

            return(Ok());
        }
Exemple #2
0
        public async Task <IHttpActionResult> ForgotPassword(PasswordRecovery model)
        {
            var user = await UserManager.FindByEmailAsync(model.Email);

            var emailConfirmed = await UserManager.IsEmailConfirmedAsync(user.Id);

            if (user != null && emailConfirmed == true)
            {
                var passwordResetToken = await UserManager.GeneratePasswordResetTokenAsync(user.Id);

                //mvc primer
                //var confirmationLinkBackend = new Uri(Url.Link("ResetPasswordRoute", new { userId = user.Id, token = passwordResetToken }));
                //SendEMailHelper.Send(user.Email, "Reset your password for transport service", "Please confirm your password reset by clicking <a href=\"" + confirmationLinkBackend + "\">here</a>");


                var confirmationLinkFrontend = new Uri("http://localhost:4200/password-recovery").AddQuery("email", model.Email).AddQuery("token", passwordResetToken);
                SendEMailHelper.Send(user.Email, "Reset your password for transport service", "Please confirm your password reset by clicking <a href=\"" + confirmationLinkFrontend + "\">here</a>");
            }

            return(Ok("If you have account with that email address on our platform you will recieve link for password reset."));
        }
Exemple #3
0
        public async Task <IHttpActionResult> Register()
        {
            var httpRequest = HttpContext.Current.Request;

            var email = httpRequest.Form.Get("email").ToString();

            //check if user with that username already exists in db
            var dbUser = unitOfWork.User.GetAll().Where(u => u.Email == email).FirstOrDefault();

            if (dbUser != null)
            {
                return(BadRequest("Korisnik sa tim korisnickim imenom vec postoji, probajte drugo!"));
            }


            var samoDavidim = httpRequest.Files;

            string status   = "not verified";
            var    utId     = ConvertStringToInt(httpRequest.Form.Get("usertype"));
            var    userType = unitOfWork.UserType.Find(x => x.TypeOfUser == utId).FirstOrDefault();
            //if (httpRequest.Form.Get("usertype") != "Obican")
            //    status = "not verified";


            var username = $"{httpRequest.Form.Get("email").Split('@')[0]}@{httpRequest.Form.Get("email").Split('@')[1].Split('.')[0]}";
            var user     = new ApplicationUser()
            {
                Id           = httpRequest.Form.Get("email").Split('@')[0],
                UserName     = username,
                Email        = httpRequest.Form.Get("email"),
                PasswordHash = ApplicationUser.HashPassword(httpRequest.Form.Get("password")),
                DateOfBirth  = DateTime.Parse(httpRequest.Form.Get("date")),
                Adress       = httpRequest.Form.Get("address"),
                Name         = httpRequest.Form.Get("name"),
                Surname      = httpRequest.Form.Get("surname"),
                Status       = status,
                UserTypeID   = userType.UserTypeID,
                Files        = "",
                AcceptedTOS  = bool.Parse(httpRequest.Form.Get("tos"))
            };

            IdentityResult result = UserManager.Create(user);

            if (!result.Succeeded)
            {
                return(GetErrorResult(result));
            }
            else
            {
                UserManager.AddToRole(user.Id, "AppUser");

                var emailToken = await UserManager.GenerateEmailConfirmationTokenAsync(user.Id);

                var confirmationLinkFrontend = new Uri("http://localhost:4200/email-send").AddQuery("email", user.Email).AddQuery("token", emailToken);
                ///var confirmationLink = new Uri(Url.Link("ConfirmEmailRoute", new { userId = user.Id, token = emailToken }));

                SendEMailHelper.Send(user.Email, "Confirm your email for transport service", "Please confirm your email by clicking <a href=\"" + confirmationLinkFrontend + "\">here</a>");

                if (httpRequest.Files.Count > 0)
                {
                    var path = GetUserFolderPath(user.Id);
                    CreateUserFolder(path);

                    List <string> uploadedFiles = new List <string>();
                    foreach (string file in httpRequest.Files)
                    {
                        var uploadedFile = httpRequest.Files[file];

                        if (IsCorrectFileExtension(uploadedFile.FileName))
                        {
                            uploadedFile.SaveAs(path + "/" + uploadedFile.FileName);
                            uploadedFiles.Add(uploadedFile.FileName);
                        }
                    }

                    if (uploadedFiles.Count > 0)
                    {
                        if (user.Files != null && user.Files.Length > 0)
                        {
                            user.Files += "," + string.Join(",", uploadedFiles);
                        }
                        else
                        {
                            user.Files = string.Join(",", uploadedFiles);
                        }

                        user.Status = "processing";
                        UserManager.Update(user);
                    }
                }
            }

            return(Ok(user));
        }