示例#1
0
        public IHttpActionResult PostEmployee(Employee employee)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(BadRequest(ModelState));
                }
                if (DBOperations.IsUsernameExist(employee.UserName))
                {
                    return(BadRequest("Username Already Exists"));
                }
                if (DBOperations.IsEmailExist(employee.Email_ID))
                {
                    return(BadRequest("Email ID Already Exists"));
                }
                employee.IsEmailVerified = false;

                string VerificationCode = Guid.NewGuid().ToString();
                var    userName         = Encode.Base64Encode(employee.UserName);
                var    link             = "http://localhost:4200/setpassword/" + HttpUtility.UrlEncode(userName);
                VerificationLink.EmailGeneration(employee.Email_ID, VerificationCode, link);

                db.Employees.Add(employee);
                db.SaveChanges();
                DBOperations.UpdateUserinfo(employee.ID, employee.UserName);
                CallStoredProc.RunLeaveEntryForNew(employee);
                return(Ok("Successfully Added"));
            }
            catch (Exception ex)
            {
                LogFile.WriteLog(ex);
                return(BadRequest());
            }
        }
示例#2
0
        public IHttpActionResult PostEmployee(Employee employee)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (DBOperations.IsUsernameExist(employee.UserName))
            {
                return(Conflict());
            }
            if (DBOperations.IsEmailExist(employee.Email_ID))
            {
                return(Conflict());
            }
            employee.IsEmailVerified = false;

            string VerificationCode = Guid.NewGuid().ToString();
            var    link             = HttpContext.Current.Request.Url.AbsoluteUri + "/VerifyAccount/" + employee.UserName;

            VerificationLink.EmailGeneration(employee.Email_ID, VerificationCode, link);

            db.Employees.Add(employee);
            db.SaveChanges();
            CallStoredProc.RunLeaveEntryForNew(employee);
            return(Ok("Successfully Added"));
        }
示例#3
0
        /// <summary>
        /// Performs an activation of the verification link.
        /// </summary>
        /// <returns>
        /// If the link does not exist the method returns null.
        /// If the link is already activated the method returns false.
        /// If the link exists and was not activated the method returns true.
        /// </returns>
        public async Task <bool?> ActivateLinkAsync(string link)
        {
            try
            {
                var filter = new EqualityFilter <string>("link", link);
                VerificationLink verificationLink = (await verificationLinksDatabase.Get(filter)).FirstOrDefault();

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

                if (verificationLink.Used)
                {
                    return(false);
                }

                verificationLink.Used = true;
                await verificationLinksDatabase.Update(verificationLink, new[] { "Used" });

                return(true);
            }
            catch (Exception ex)
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("Error occured while working with the database");
            }
        }
示例#4
0
        public IHttpActionResult ForgotPassword(ForgotPassword pass)
        {
            var employee = DBOperations.IsEmployeeExist(pass.UserName);

            if (employee == null)
            {
                return(NotFound());
            }
            else
            {
                string VerificationCode = Guid.NewGuid().ToString();
                var    link             = HttpContext.Current.Request.Url.AbsoluteUri + "/ForgotPassword/" + employee.UserName;
                VerificationLink.EmailGeneration(employee.Email_ID, VerificationCode, link, "ResetPassword");
                return(Ok(employee));
            }
        }
示例#5
0
        public async Task <string> CreateVerificationLinkAsync(UserInfo user)
        {
            try
            {
                VerificationLink link = new VerificationLink(user);

                await verificationLinksDatabase.Connect();

                await verificationLinksDatabase.Insert(link);

                return(link.Link);
            }
            catch (Exception ex)
            {
                exceptionLogger.Log(new ApplicationError(ex), LogLevel.Error, logConfiguration);
                throw new DatabaseException("Error occured while working with the database");
            }
        }
示例#6
0
 public IHttpActionResult ForgotPassword(ForgotPassword pass)
 {
     try
     {
         var employee = DBOperations.IsEmployeeExist(pass.UserName);
         if (employee == null)
         {
             return(NotFound());
         }
         else
         {
             string VerificationCode = Guid.NewGuid().ToString();
             var    userName         = Encode.Base64Encode(employee.UserName);
             var    link             = "http://localhost:4200/setpassword/" + HttpUtility.UrlEncode(userName);
             VerificationLink.EmailGeneration(employee.Email_ID, VerificationCode, link, "ResetPassword");
             return(Ok("Reset Link has been sent to your mail id"));
         }
     }
     catch (Exception ex)
     {
         LogFile.WriteLog(ex);
         return(BadRequest());
     }
 }